What will be the instruction sequence that implements PUSH R4?
A: SUB SP, SP, #4
STR R4, [SP, #0]
B: STR R4, [SP, #0]
SUB SP, SP, #4
C: ADD SP, SP, #4
STR R4, [SP, #0]
D: STR R4, [SP, #0]
ADD SP, SP, #4
E: All of the above are possible
The correct answer is E, but I don't quite follow.
For A, SP
would point at the current stack value, and then the SUB
command would move it to a new empty place in the stack where R4
is then stored.
For B, R4
is stored at the current place in the stack and then the stack pointer moves to an empty space. Wouldn't this overwrite the current value in the stack when R4
is written?
For C and D, wouldn't the ADD
move it back from the stack? So in C, R4
overwrites a value, and in D, the next value pushed onto the stack would overwrite R4
?