92%(13)12 out of 13 people found this document helpful
This preview shows page 7 - 9 out of 9 pages.
Problem 4: Assembly Programming (15 points)Consider the X86 32-bit assembly code.puzzle:pushl%ebpmovl%esp, %ebpmovl12(%ebp), %eaxmovl(%eax), %eaxmovl8(%ebp), %edximull(%edx), %eaxpopl%ebpret•(2 points) How many memory accesses are performed by the body of thepuzzlefunction excludingstack pushes and pops?•13 points Write the C code for the above assembly? Clearly show the function body, function signa-tures and function return values?7
Problem 5: Assembly Programming (25 points)1. (9 points) Consider the below assembly code.movl (%eax), %edxmovl (%edx), %ebxIf the register%eaxmaps to a C variablepand the register%edxmaps to a C variableq.•What is the data type ofpin C?•What is the data type ofqin C?•Write the equivalent C code for the above operation?2. (6 points) Are these operations legal? If not, why?3. (6 points) What is the effective address for each of the following:%eax: 15%edx: 0x40%ebp: 0x6000(a) 0x4(%ebp):(b)(,%ebp,4):(c)(%ebp,%edx,4):8
4. (4 points) When you generate assembly code, you often see the following code.test %eax, %eaxWhy does the compiler generate this code? What is another alternative way of performing the sameoperation?9