What does the "retn" statement mean with an argument?

Asked

Viewed 81 times

-1

Is it possible to see return instructions with an argument, how this is done and how the return value is treated? It is to return an argument in the stack?

Immunity Debugger, NTDLL, Windows

2 answers

3


When the code will return from a routine it must specify how many bytes it should return to the stack by changing the Stack Pointer (SP) register. That’s the number there.

Note that the numbers are always multiples of 4 bytes which is the size of a word in architecture then it is returning the amount of words determined by that number divided by 4. Do not forget that it is in hexadecimal.

The N indicates that you must do this within the code segment itself. In the past 16 buts codes could only address 64KB and to get more memory was required to use multiple segments through a so-called distant addressing (far) and there used to be instruction RETF, unless it was only in the same segment that uses the RETN (near). IN modern codes there is only one segment, but even in the past it was rarer to leave the segment for this kind of end.

The RET in fact is the RETN (or RETF if necessary), but the assembler infers how many bytes should return on the stack pointer.

That’s the x86 Assembly, don’t watch out for other flavors.

0

You can see:

  1. It is common to have this instruction at the end of the Epilogue of the function.
  2. When used, always changes the ESP and EIP.
  3. It is sometimes used to exit the "Current segment"

I will read and do some tests too, then put here! ; also I was a little curious now rs ... I really liked the intention of the Post, also I think it is nice to give a thorough in the x86 family instructions ! ;)

For reference: https://www.felixcloutier.com/x86/ret

Vlw by post, and turn an interesting Thread !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.