I have the following piece of ARM Assembly Code from my professor. I do not understand why i need to move the stack pointer to r1 and what happens exactly.
I know from the lecture, that ...
The stack pointer is pointing to the last written value on the stack.
Does pointing to always mean that the address is stored? I managed to get the code working. But i want to improve code quality and understand what's going on. Also i am not allowed to use arithmetic operations anywhere in the program. i tried the debugger also. but i only figured out how to watch the program counter from there. I used
info registers sp pc
and
disas
I searched through all the options of the debugger but could not find something helpful.
In the stack pointer register is stored - i guessed - some address value.
// scan for users answer 'y'
ldr r0, =charplace
mov r1, sp @ ???
bl scanf @ Scan user's answer
ldr r1, =yes @ Put address of 'y' in r1
ldrb r1, [r1] @ Load the actual character 'y' into r1
at the start of the main function i do this:
.global main
main:
push {r4 - r7, lr} @ copy values of these reg on top of the stack
sub sp, sp, #4 @ needs to be replaced ! TODO
and at the end this:
end: add sp, sp, #4 @ needs to be replaced ! TODO
pop {r4 - r7, pc} @ copy values from the top of the stack back into these registers