The Stack Flashcards
What does the PUSH instruction do?
PUSHes a value onto the top of the stack.
What does the POP instruction do?
POPs a value off the top of the stack.
What happens to the ESP when you PUSH a value on to the stack?
The memory address decreases as the stack grows.
What happens to the ESP when you POP a value off of the stack?
The memory address increases as the stack shrinks.
Which register is pushed onto the stack at the beginning of a new function?
EBP (base pointer of the previous stack frame)
How would you reserve space on the stack for a local variable?
“SUB ESP, 10” would reserve 10 (hex) bytes of data on the stack
After pushing the previous functions EBP to the stack, what do we do with the EBP?
“MOV EBP, ESP”. We set the value of EBP to the current ESP to create the new stack frame for the current scope of the function
When returning out of a function back to the original, how do we obtain the previously used stack frame?
“MOV ESP, EBP; POP EBP;” sets the ESP to the original EBP, removing the previous stack frame data, and POPs the value off of the top into EBP. This is the original EBP which recreates the stack frame.
Which three instructions are likely to be seen at the end of a function that returns to main() ?
“MOV ESP, EBP” -> clear the stack back to main() stack frame
“POP EBP” -> restore the base pointer of main()
“RETN” -> return to main()
If the ESP is “0x0012E650” and 2 registers are PUSH’d, what is the new value of the ESP?
0x0012E648 or “ESP - 8”
If the ESP is “0x0012E650” and 2 registers are POP’d, what is the new value of the ESP?
0x0012E658 or “ESP + 8”