My professor assigned a homework assignment and it went like this. This is ARM Assembly, and imagine this is an Empty Descending stack. This means memory addresses move from higher addresses to lower addresses, and empty means the stack pointer points to the empty space above the stack. In this example, the addresses are in brackets. I'll use | | for empty space. TOS is the top of the stack and SP is the current position of the stack frame.
|___| (80)
|___| (84)
|___| (88)
|___| SP (92)
|___| TOS (96)
|___| (100)
Here is the code in question. I'll explain what I think happens after each line
STMED sp!, {fp,lr}
(FP is R11 and LR is R13. Because lower registers go in lower addresses, the current value FP is stored in 88 and LR is stored in 92. The stack is an ED stack, so SP is at 84, a spot above FP)MOV fp,sp
(FP now points to the same location as SP, 84. The previous value of FP is stored at position 88)SUB SP,SP,#4
(SP points to 80)STR R3, [fp, #12]
(FP is 84, so R3 is stored in 84+12 which is equal to 96, replacing the old TOS)STR R6, [fp,#-4]
(R6 is stored in 84-4 which is 80)
So this is my logic and it makes sense to me, but my professor said I was wrong. She said I should not use the location FP points to, but the value of FP that was put on the stack (which is at position 88). Meaning R3 would be stored at spot 100 and R6 stored at point 84. She was adamant that this is right, and said the frame pointer cannot be changed once it's put on the stack and it is the base of the stack frame. I understand all that, but I don't understand her logic. We are storing the value on the stack then changing it to point to something else. Why are we still using the old value? Can someone explain this to me?