Question: #include #include / * compute x * y with addition * / uint 6 4 _ t recmul ( uint 6 4 _ t a

#include
#include
/* compute x*y with addition */
uint64_t recmul(uint64_t a,uint64_t b){
if (a==0|| b==0)
return 0;
else if (a==1)
return b;
else
return b + recmul(a-1,b);
}
/* compute x to the yth power using only addition */
uint64_t recexp(uint64_t x,uint64_t y){
if (y ==0)
return 1;
else if (y==1)
return x;
else
return recmul(x,recexp(x,y-1));
}
int main(){
printf("recexp(2,2) returned %lu.
",recexp(2,2));
return 0;
}
Using the disassemble command under gdb, examine the first five instructions of
recmul (ignoring the endbr64 instruction).
1
a. Compare these instructions to the first five instructions of recexp. What do you notice?
b. What are these instructions doing? (Hint: recall that the parameters to each function are
passed in registers %rdi and %rsi.)
c. Why does the compiler generate this code? (Hint: look at the instructions before the recursive
call in each function.)

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!