The stack pointer, like its name, has a pointer, like any other, and points to normal standard memory. To access any area of the stack, simply add an offset to the pointer.
If you think about it in terms of C pointers, you have a stack pointer
char *stack_pointer = some_memory;
This pointer can then be used as a regular pointer, including adding offsets to access specific places on the stack, for example,
*(int *)(stack_pointer + 4) = 5;
I recommend that you try to find out the assembler code, then you can make a very simple program with several local variables and compile it into assembler code and read it to see exactly how it works.
source
share