Hi, I have this homework assignment, please help! I'm new to C programming.
HW4-1 (50 points): Consider the following assembly code:
movl $1, %edx ; line 1
xorl %eax, %eax ; line 2
movzbl %sil, %ecx ; line 3
movb %dl, %sil ; line 4
salq %cl, %rdx ; line 5
andq %rdi, %rsi ; line 6
xorq %rsi, %rax ; line 7
testq %rdx, %rdx ; line 8
jne .L3 ; line 9
ret ; line 10
.L3:
; loop code goes here
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 accu;
long loopvar;
for (loopvar = 0; loopvar < num; loopvar++) {
accu += z;
}
return accu;
}
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, %rcx, %r8, and %r9 or portions thereof in that order.
A. Which registers hold program values z and num? (24 pts)
B. In which assembly code line number is accum updated on each iteration of the loop? (3 pts)
C. In which assembly code line number is loopvar updated on each iteration of the loop? (3 pts)
D. What are the initial values of accum and loopvar? (23 pts)
E. What is the test condition for loopvar? (5 pts)
F. How does loopvar get updated? (5 pts)
G. How does accu get updated? (5 pts)
H. Fill in all the missing parts of the C code. (11 pts) for doing correctly based on the above answers