Question: Consider the following assembly code long loop(long x, int n) x in %rdi, n in %esi 1 loop: movl movl movl %esi, %ecx $1,%eax $0,%eax

 Consider the following assembly code long loop(long x, int n) xin %rdi, n in %esi 1 loop: movl movl movl %esi, %ecx

Consider the following assembly code long loop(long x, int n) x in %rdi, n in %esi 1 loop: movl movl movl %esi, %ecx $1,%eax $0,%eax 4 ?2 6 .L3: movq %rdi, %r8 org 11 L2: 12 13 %rax , ?3 testq %rdx ne rep; ret The preceding code was generated by compiling C code that had the following overall form: 1 long loop(long x, long n) long result long mask; for (nask 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 %rax. 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. Fill in all the missing parts of the C code Consider the following assembly code long loop(long x, int n) x in %rdi, n in %esi 1 loop: movl movl movl %esi, %ecx $1,%eax $0,%eax 4 ?2 6 .L3: movq %rdi, %r8 org 11 L2: 12 13 %rax , ?3 testq %rdx ne rep; ret The preceding code was generated by compiling C code that had the following overall form: 1 long loop(long x, long n) long result long mask; for (nask 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 %rax. 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. Fill in all the missing parts of the C code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!