Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. Consider the following assembly code: // x at %ebp + 8, n at %ebp + 12 movl movl movl movl 8(%ebp ) , %esi
1. Consider the following assembly code: // x at %ebp + 8, n at %ebp + 12 movl movl movl movl 8(%ebp ) , %esi 12 ( %ebp ) , %ebx $-1, %edi $1, %eax 5.L2 movl and1 xor1 movl sall %edx , %eax %esi, %eax %eax , %edi %ebx, %ecx %cl, %edx 10 11 test1%edx ,%edx 12 jne L2 13 movl %edi,eax The preceding code was generated by compiling C code that had the following overall form int loop(int x, int n) int result = int mask; for (mask - -; mask ; mask = result return result; Your task is to fill in the missing parts of the C code to get a program equivalent to the generated assembly code. Recall that the result of the function is returned in register eax You will find it helpful to examine the assembly code before, during, and after the loop to form a consistent mapping between the registers and the program variables A. Which registers hold program values x, n, result, and mask? B. What are the initial values of result and mask? C. What is the test condition for mask? D. How does mask get updated? E. How does result get updated? F. Fil in all the missing parts of the C code
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started