When you use this stack pointer in function be sure pop everything from the stack before returning , cause the return instruction expect the return address to be in the top of the stack .
Excellent video - really beyond what I expected for a YT video. Thanks very much, saved me on my final! Also...is this dude writing backwards for the camera??
good vid sir, ,so basically stack is a certain set of memory locations right... and it may or maynot have values in it. so the stack pointer points to the top of the stack...and with that u can store or remove stuff from the stack using push or pop?
Yes, it's just memory. Of course a number of mechanisms have been added by both hardware and the operating system to make it more secure, but push and pop are basically putting items on and taking items off the stack.
Is the memory that the stack uses manually addressable? That is could I do sth. like `orr r4, sp` and then `str r5, [r4]`? Is the stack-memory a system-defined thing completely separate from any heap-address-space, or can there be overlap? Also, is the stack-pointer automatically initialized to sth. legit, or does the programmer have to care for this?
That's the key. The elements of the stack have no identification of where they came from. Your (assembly language) code is responsible for maintaining the correct order of pushes and pops.
It depends on how the architect designed the stack to operate. (In fact, some processors allow the programmer to decide!) From the programmer's point of view, however, you can push any registers in any order onto the stack. To restore those registers, you simply pop off in the opposite order that you pushed.