首页 > 其他 > 详细

ASM:ret,retn,retf

时间:2020-03-26 13:10:30      阅读:78      评论:0      收藏:0      [点我收藏+]

enter code:
push ebp
mov ebp, esp

leave code:
mov esp,ebp
pop ebp

classic example:
enter
sub esp, 8
leave
retn 10h

In the mnemonic ret N, N is the size of parameters on the stack.
In this case it is 4 * 4 = 16 (10h) for 4 DWORDs.
But this only applies to calling conventions when the callee is responsible for stack cleanup.
In case of cdecl convention the ret should be without any numbers,
as the caller is responsible for stack cleanup.

If you substitute the function epilog with ret 0ch,
then the content of ebp will be incorrect in the calling function.


ret:retn
retn:pop eip
retf:pop eip;pop cs

It‘s actually two types: retn and retf.
The third one ret is coded by the assembler into one of the first two.
The difference is that retn (return near) will pop the instruction pointer (IP) only.
While the retf (return far) will pop both the instruction pointer (IP) and the code segment (CS).

proc far
retf

proc near
retn


C3 RETN
C2 0400 RETN 4
90 NOP
CB RETF
CA 0400 RETF 4

FACTORIAL_COMPUTE PROC
PUSH DX
MOV DX,AX
CMP AX,0
JZ DONE

DEC AX
CALL FACT


MUL DX
POP DX
RET


DONE:
MOV AX,1
POP DX
RET
FACTORIAL_COMPUTE ENDP

ASM:ret,retn,retf

原文:https://www.cnblogs.com/xinyueliu/p/12573547.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!