Question: Consider the following assembly code mov! S1, %edx # line #1 xor! %eax, %eax # line #2 movzbl %sil, %ecx # line #3 movq %rdx.

 Consider the following assembly code mov! S1, %edx # line #1

Consider the following assembly code mov! S1, %edx # line #1 xor! %eax, %eax # line #2 movzbl %sil, %ecx # line #3 movq %rdx. %rsi # line #4 salq Xc1.Zrdx #line#5 andq %rdi. %rsi # line #6 xorq %rsi. %rax # line #7 testq %rdx, %rdx # line #8 # line #9 3: L3 ret # line #10 in which comments (beginning with #) are used to number the lines. The preceding code was generated on shannon by compiling C code that had the following overall form: long loop(long z, int num) long loopvar; accun return accum Your task is to fill in the missing parts of the C code to get a program equivalent to the generated assembly code. On the way, answer the questions below. Keep in mind that the return value of a function is returned in register %rax and the first six arguments to a function are passed in %rdi, %rsi, %rdx, %rex, 8, and %rg (or portions thereof) in that order. A. Which registers hold program values z and nun? (2x4pts) B. In which assembly code line number is accum updated on each iteration of the loop? (3pts) C. In which assembly code line number is loopvar updated on each iteration of the loop? (3pts) D. What are the initial values of accun and loopvar? (2x3pts.) E. What is the test condition for loopvar? (5pts.) F. How does loopvar get updated? (5pts.) G. How does accum get updated? (5pts.) H. Fill in all the missing parts of the C code. (11pts. for doing oorrectly based on above answers) Consider the following assembly code mov! S1, %edx # line #1 xor! %eax, %eax # line #2 movzbl %sil, %ecx # line #3 movq %rdx. %rsi # line #4 salq Xc1.Zrdx #line#5 andq %rdi. %rsi # line #6 xorq %rsi. %rax # line #7 testq %rdx, %rdx # line #8 # line #9 3: L3 ret # line #10 in which comments (beginning with #) are used to number the lines. The preceding code was generated on shannon by compiling C code that had the following overall form: long loop(long z, int num) long loopvar; accun return accum Your task is to fill in the missing parts of the C code to get a program equivalent to the generated assembly code. On the way, answer the questions below. Keep in mind that the return value of a function is returned in register %rax and the first six arguments to a function are passed in %rdi, %rsi, %rdx, %rex, 8, and %rg (or portions thereof) in that order. A. Which registers hold program values z and nun? (2x4pts) B. In which assembly code line number is accum updated on each iteration of the loop? (3pts) C. In which assembly code line number is loopvar updated on each iteration of the loop? (3pts) D. What are the initial values of accun and loopvar? (2x3pts.) E. What is the test condition for loopvar? (5pts.) F. How does loopvar get updated? (5pts.) G. How does accum get updated? (5pts.) H. Fill in all the missing parts of the C code. (11pts. for doing oorrectly based on above answers)

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!