Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Recall that the call instruction pushes the address of the next instruction after the call onto the stack, at the same time as it loads

Recall that the call instruction pushes the address of the next instruction after the
call onto the stack, at the same time as it loads the address of the function being called into the
program counter. This problem asks about the return addresses in this code. (Hint: The best way
to find the address of an instruction is to run the program under gdb, set a breakpoint (in main is
fine) and then use the disassemble command, which lists the address of each instruction next to
the assembly instruction. You can give the name of a function as an argument to disassemble to
get list only the code for that function.
a. What return address is pushed by the call recexp in main? (It should be of the form
0x00005555...)
b. What return address is pushed on the stack by the recursive call in recexp?
c. What return address is pushed on the stack by call to recmul in recexp
#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;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions