I’m trying to understand how the stack works and I have the following question that I would like to solve: after having analyzed the execution of the arm32 assembly code from the first line, assuming that the top of the stack is initially located at the address 0x00000000, what will be the value contained in sp at the execution of the statement on line 9?
-
0x00000000
-
0xFFFFFFF8
-
0xFFFFFFFC
The code is this: -
start bl subroutine1
-
end
-
subroutine1 str lr, [sp, #−4]!
-
mov r0,#2
-
mov r1,#4
-
bl subroutine2
-
ldr pc,[sp],#4
-
subroutine2 lr, [sp, #−4]!
-
cmp r0,#0
-
beq subroutine2_end
-
mov r2,r0
-
mov r0,#0
-
loop add r0, r0, r1, lsl #1
-
subs r2, r2, #1
-
bne loop
-
subroutine2_end ldr pc, [sp], #4
I tried to think in two ways: the first concerns the fact that the sp should be a preserved register and consequently since there are subroutines these must not alter it. So the value should be 0x00000000.
If I think about how to decrease the stack, however, I know that I have to decrease by a multiple of 4 and it certainly would not be a value that is reported as among the following answers.
I hope I was clear and that someone can provide me with an explanation.
Thank you