Chapter 3 Machine-Leve Representation of Programs Guobao Jiang 11210240049@fudan.edu.cn
Chapter 3 Machine-Level Representation of Programs Guobao Jiang 11210240049@fudan.edu.cn
Problem 3. 1(P138 Assume the following values are stored at the indicated memory addresses and registers: Address Value Register Value ox100 OxFF %eax Ox100 Ox104 OXAB ecX Ox1 Ox108 0x13 led Ox3 O×10C O×11 Fill in the following table showing the values for the indicated operands 2021/10/29
Problem 3.1 (P138) • Assume the following values are stored at the indicated memory addresses and registers: • Fill in the following table showing the values for the indicated operands: 2021/10/29 2 Address Value 0x100 0xFF 0x104 0xAB 0x108 0x13 0x10C 0x11 Register Value %eax 0x100 %ecx 0x1 %edx 0x3
Address Value Registervalue 0×100 OXFF % 0x100 0×104 OXAB % ecx 0×1 0×108 0×13 %edx 0×3 0×10C O×11 value Imm(Eb, E, s) Register M[Imm+ R[Eb]+ R[E]'SI XAB Absolute address $Ox1 0×108 mmediate (%eax) OxFF Address o×100 4(%ea×) OXAB Address c×104 9(%eax,%ed×) O×11 Address0×10C 260(%ecX,%ed×) O×13 Address o×108 0×FC(,%ecX,4) OxFF Address0×100 (%eax,%ed×,4) O×11 Address0×10C 2021/10/29
0xFF Address 0x100 0x13 Address 0x108 0x11 Address 0x10C 0xAB Address 0x104 0xFF Address 0x100 0x108 Immediate 0xAB Absolute address 0x100 Register 0x11 Address 0x10C Operand Value %eax 0x104 $0x108 (%eax) 4(%eax) 9(%eax, %edx) 260(%ecx, %edx) 0xFC(, %ecx, 4) (%eax, %edx, 4) 2021/10/29 3 Address Value 0x100 0xFF 0x104 0xAB 0x108 0x13 0x10C 0x11 Register Value %eax 0x100 %ecx 0x1 %edx 0x3 Imm(Eb , Ei , S) M[Imm + R[Eb ] + R[Ei ]*S]
Problem 3.2( P142 you are given the following information. A function with prototype void decode(int xp, int yp, Int zI is compiled into assembly code. The body of the code is as follows: Parameters xp, yp and zp are stored at memory locations with offsets 8, 12, and 16, respectively, relative to the address in register ebl 2021/10/29
Problem 3.2 (P142) • You are given the following information. A function with prototype void decode1(int *xp, int *yp, int *zp) is compiled into assembly code. The body of the code is as follows: … • Parameters xp, yp and zp are stored at memory locations with offsets 8, 12, and 16, respectively, relative to the address in register %ebp 2021/10/29 4
Problem 3.2+ 1 movl 8 (%ebp),%edi 2 movl 12(%ebp), ebx int x =*xp 3 movl 16(%ebp), %esi int y ="yp int z=zp, 4 movI (%edi, %eax yP=X, 5mov(‰ebx),%ed zp=y 6 movl (%esi, %ecx 7mov%eax,(%eb×) 8 movl %edx, (%esi 9 movl %ecx, c%edi Write C code for decode1 that will have an effect equivalent to the assembly code above 2021/10/29
Problem 3.2+ 1 movl 8(%ebp), %edi 2 movl 12(%ebp), %ebx 3 movl 16(%ebp), %esi 4 movl (%edi), %eax 5 movl (%ebx), %edx 6 movl (%esi), %ecx 7 movl %eax, (%ebx) 8 movl %edx, (%esi) 9 movl %ecx, (%edi) • Write C code for decode1 that will have an effect equivalent to the assembly code above. 2021/10/29 5 int x = *xp; int y = *yp; int z = *zp; *yp = x; *zp = y; *xp = z;