When a call
happens, it is my understanding that the address of the caller is pushed onto the stack, and when a ret
is executed, it jumps to the popped value from the stack.
What happens if I push a value and forget to pop it? Wouldn't ret
simply pop
what it expects to be the return address from the stack and be sorely mistaken by whatever value was actually at the top of the stack? E.g:
Function:
mov ax, "A"
push ax
ret
call Function
Additionally, I wonder the same thing about pusha
and popa
. If I push
a value after a pusha
does the popa
now use that value when it pops however many registers it uses, leaving the original first register on the stack and restoring every register to the register + 1's value?