I am very new to assembly, and I don't understand what it exactly means when, at the end of a proc, you write a number with the ret
statement.
Like this:
Function Proc push ax cx . ...body... . pop cx ax ret 2 Function endp
I understand it has something to do with where the stack pointer should return to at the end of the function?
What does it do?
Yes, but ret 2
also removes 2 bytes of parameters from the stack. Presumably, your function was called like:
push some_parameter call Function
At this point, a cdecl
function - a "caller cleans up" function (Generally used by C) - would require add sp, 2
to "clean up the stack", removing the parameter. Such a function would end in a plain ret
.
A stdcall
function, which is what you've got, is a "callee cleans up" function (used by Windows APIs, for example) doesn't require the add sp, 2
- it has been done by the ret 2
.
If you're not aware of it, call
puts the return address on the stack (and ret
pops it off), so you can't just pop
to get the parameter inside your function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With