I'm completely new to Assembly and looking to confirm where, in the following statements, I have a misunderstanding and need to be corrected.
The stack pointer (ESP
) refers to the top (lowest memory address) of the stack.
The base Pointer (EBP
) is used for temporarily storing various memory addresses when building a stack frame. It normally holds the highest memory address of the current stack frame.
The instruction pointer (EIP
) refers to the memory address of a line of code in the text (code) segment of memory
Once something has been pushed to the stack, it can't be changed in-place. ie. If we PUSH EBP
to the stack, we are pushing the current value of EBP
, not some kind of reference or pointer to it. We can't then change that value in-place.
Arguments being passed into a function are generally moved into an address space which is an offset of the stack pointer. ie. [ESP-12]
.
When a function is called (using CALL
), the following occurs:
- The return address is added to the stack (the memory of the address immediately following the current
EIP
so we know where to return to after the called function has completed - The saved frame pointer is added to the stack, which is normally the stack pointer of the stack frame of the calling function
- We would then move into the prologue of the called function
Thanks. I'm trying to get my head around this stuff.