Chapter 4 Processor Architecture

Homework Problems

对于要求写汇编代码,我一无所知…

4.45

Chapter 4 Processor Architecture_第1张图片
A: When REG is %rsp, it can not correctly describe. Because it will push %rsp - 8 not %rsp.
B:

movq REG, -8(%rsp)
subq $8, %rsp

4.46

Chapter 4 Processor Architecture_第2张图片
A: When REG is %rsp, it can not correctly describe. Because the value of %rsp is (%rsp) + 8, not (%rsp).
B:

addq $8, %rsp 
movq -8(%rsp), REG

4.47

Chapter 4 Processor Architecture_第3张图片
A:

/*Bubble sort: pointer version */
void bubble_a(long *data, long count)
{
     
    long i, last;
    for (last = count - 1; last > 0; last--)
    {
     
        for (i = 0; i < last; i++)
        {
     
            if (*(data + i + 1) < *(data + i))
            {
     
                /*Swap adjacent elements */
                long t = *(data + i + 1);
                *(data + i + 1) = *(data + i);
                *(data + i) = t; 
            }
        }
    }
}

4.48

Chapter 4 Processor Architecture_第4张图片

4.49

在这里插入图片描述

4.50

4.51

Chapter 4 Processor Architecture_第5张图片

iaddq V, rB 

Fetch:
    icode : ifun <-- M1[PC] = C : 0
    rA : rB <-- M1[PC + 1] = F : rB 
    valC <-- M8[PC + 2]
    valP <-- PC + 10

Decode:
    valB <-- R[rB]

Execute:
    valE <-- valB + valC

Memory:

Write back:
    R[rB] <-- valE;

PC upate:
    PC <-- valP 

4.52

Chapter 4 Processor Architecture_第6张图片
到这里就没必要了,看到很多大佬这章学的很好,比不了…下章继续努力

.我就是个酸菜鱼,又酸又菜又多余

你可能感兴趣的:(CSAPP)