Question: Suppose the stack pointer SP is initialized to 0 x 2 0 0 0 0 6 0 0 . A recursive function A recursive assembly

Suppose the stack pointer SP is initialized to 0x20000600.
A recursive function A recursive assembly code
int factorial(int n);
int main(void){
factorial(3);
return 0;
}
int factorial(int n){
int f;
if(n==1)
return 1;
else
f = n*factorial(n1);
return f;
}
0x08000130
0x08000134
0x08000136
0x08000138
0x0800013A
0x0800013C
0x0800013E
0x08000140
0x08000142
0x08000144
0x08000148
0x0800014C
AREA main, CODE, READONLY
EXPORT __main
ENTRY
__main PROC
MOV r0, #0x03
BL factorial
stop B stop
ENDP
factorial
PUSH {r4, lr}
MOV r4, r0
CMP r4, #0x01
BNE NZ
MOVS r0, #0x01
loop POP {r4, pc}
NZ SUBS r0, r4, #1
BL factorial
MUL r0, r4, r0
B loop
END
Show the stack content when factorial(1) is returned.
0x20000618
0x20000614
0x20000610
0x2000060C
0x20000608
0x20000604
0x20000600
0x200005FC
0x200005F8
0x200005F4
0x200005F0
0x200005EC
0x200005E8
0x200005E4
0x200005E0
0x200005DC
0x200005D8
0x200005D4
0x200005D0
0x200005CC
0x200005C8
0x200005C4

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 Programming Questions!