PLEASE ANSWER ALL THE 7 QUESTION IN THIS PICTURE................THANKS Long loop
ID: 3886380 • Letter: P
Question
PLEASE ANSWER ALL THE 7 QUESTION IN THIS PICTURE................THANKS
Long loop(long x, long n) long result = ___________: long mask: for (mask =__________;mask _________;mask = __________){} 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 %tax. 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.Explanation / Answer
A. Which registers hold program values x, n, result, and mask?
| Variable| | Register |
result.
F. Fill in all the missing parts of the code.
long loop(long x, long n) {
long result= -1;
A. Which registers hold program values x, n, result, and mask?
| Variable| | Register |
| x | ---> | %esi | | n | ---> | %ebx | | result| ---> | %edi | | mask | ---> | %edx | B. What are the initial values of result and mask? The initial value for result is -1 and the initial value for mask is 1 C. What is the test condition for mask? The condition that test mask is mask not equal to zero(mask not zero). D. How does mask get updated? The mask value is holds by the register %edx, therefore mask get updated every time %edx is shifted to the left by n bits in line 10, test the instruction in line 11 only changes the flags and does not change the register value. E. How does result get updated? The result is updated Bitwise applied on mask and x and the result XORed withresult.
F. Fill in all the missing parts of the code.
long loop(long x, long n) {
long result= -1;
long mask; for (mask =1; mask !=0; mask = mask<<n) { result ^= (mask & x); } return result; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.