Show the contents of the ARM function call stack just after each C function has
ID: 3680929 • Letter: S
Question
Show the contents of the ARM function call stack just after each C function has been entered and just after the function exits. Assume that the function call stack is empty when main() begins.
The code is as given:
int foo(int x1, int x2) {
return x1+x2;
}
int bac(int x1) {
retun x1+1;
}
int scum(int ) {
for (i = 0; i = 2; i++)
foo(r + i, 5);
}
main ()
scum(3);
baz(2);
}
note:The function call / runtime stack sequence is easiest to illustrate with an excel sheet with
each column cooresponding to a call/return site, and the stack elements shown in the vertical
rows
Explanation / Answer
Before starting I am assuming the following defintion for scum which you might have written wrong .
void scum(int r)
{
for (i = 0; i <= 2; i++)
cout<<foo(r + i, 5);
}
Let's start with main.
First function call is scum(3).
Inside it's definition, here r = 3
for i=0
foo(r+i,5) = foo(3,5) is called.
Now the control goes to foo function which will return the sum of 3 and 5 which is 8 and that will be printed.
for i=1 and r=3
foo(r+i,5)=foo(4,5) is called
Now the control goes to foo function which will return the sum of 4 and 5 which is 9 and that will be printed.
for i=2 and r=3
foo(r+i,5)=foo(5,5) is called
Now the control goes to foo function which will return the sum of 5 and 5 which is 10 and that will be printed.
Now the work of scum has been completed.Let's move to the next line baz(2) in the main.
baz() is called and Now the control goes to baz function which will increment the value given as argument which is 2+1=3 and that will be printed or returned.
Main function
Scum function
Baz/Bac function
Note:- Stack values are shown from left to right.
Program codes are shown from top to bottom.
1 main() 2 scum(3) foo(3,5) for i=0 foo(4,5) for i=1 foo(5,5) for i=2 3 baz(2)Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.