Question: #include #include / * compute x * y with addition * / uint 6 4 _ t recmul ( uint 6 4 _ t a
#include
#include
compute xy with addition
uintt recmuluintt auintt b
if a b
return ;
else if a
return b;
else
return b recmulab;
compute x to the yth power using only addition
uintt recexpuintt xuintt y
if y
return ;
else if y
return x;
else
return recmulxrecexpxy;
int main
printfrecexp returned lu
recexp;
return ;
In this problem you will trace the evolution of
the state of the stack across the series of recursive calls. With each function call the return address
and the contents of some registers are stored in the stack, creating what we call a stack frame for
that invocation of the function.
For this problem you will diagram the changes to the state of the stack by indicating the function
invoked and the parameters to that function, and the return address to which that function will
return when that invocation completes execution. An example of what this looks like for the given
code, with main invoking recexp is shown below. In these diagrams, lower addresses are at
the bottom of each stack; thus the stack grows downward in the figures. We dont care about the
return address from main.
Create a similar sequence of diagrams showing the stack evolution if the call from main is recexp
Hint Use gdb Set breakpoints in the two recursive functions, and each time you hit a breakpoint,
use the where command. Note that stack frames are listed in gdb from the top down.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
