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?
Asked
Active
Viewed 175 times
-1
-
Have you read the documentation? See [here](https://c9x.me/x86/html/file_module_x86_id_280.html). You are only interested in the pseudo-code for “near return.” – fuz Dec 19 '18 at 12:43
-
yes , I was able to read it – user10416143 Dec 21 '18 at 01:39
1 Answers
1
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.

Peter Cordes
- 328,167
- 45
- 605
- 847