Search code examples
assemblyx86returnmasm32

The question is related to Assembly x86-32 RET n instruction


I know the meaning of Ret n but I can't figure out its role to maintaining program's runtime stack? I'm kind of confuse there. Do ret have somethig to do with stack?


Solution

  • ret n is like ret + add esp, n. You use it for caller-pops calling conventions.

    Plain ret is like pop eip. (pop eip isn't a valid instruction, but it nicely expresses what ret does). Yes it uses the stack; read the documentation. http://felixcloutier.com/x86/RET.html (specifically the "near return" part.)

    "far ret" is more complicated, but not used in 32 or 64-bit code with a flat memory model. i.e. not used at all in normal code.