Question
Consider the following assembly code: long loop(long x, int n) x in %rdi, n in %esi 1 loop: 2 movl %esi, %ecx 3 movl $1,
Consider the following assembly code:
long loop(long x, int n)
x in %rdi, n in %esi
1 loop:
2 movl %esi, %ecx
3 movl $1, %edx
4 movl $0, %eax
5 jmp .L2
6 .L3:
7 movq %rdi, %r8
8 andq %rdx, %r8
9 orq %r8, %rax
10 salq %cl, %rdx
11 .L2:
12 testq %rdx, %rdx
13 jne .L3
14 rep; ret
The preceding code was generated by compiling C code that had the following overall form:
1 long loop(long x, long n)
2 {
3 long result = ;
4 long mask;
5 for (mask =______ ; mask=______ ; mask =______ ) {
6 result |=______ ;
7 }
8return result;
9 }
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.
1 long loop(long x, long n)
2 {
3 long result = ;
4 long mask;
5 for (mask =______ ; mask=______ ; mask =______ ) {
6 result |=______ ;
7 }
8return result;
9 }
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