|
ret详解: RET—Return from Procedure Opcode Instruction Description C3 RET Near return to calling procedure ;短返回 CB RET Far return to calling procedure ;长返回 C2 iw RET imm16 Near return to calling procedure and pop imm16 bytes from stack ;带参数的短返回 CA iw RET imm16 Far return to calling procedure and pop imm16 bytes from stack ;带参数的长返回
Description This instruction transfers program control to a return address located on the top of the stack. The address is usually placed on the stack by a CALL instruction, and the return is made to the instruction that follows the CALL instruction. The optional source operand specifies the number of stack bytes to be released after the return address is popped; the default is none. This operand can be used to release parameters from the stack that were passed to the called procedure and are no longer needed. It must be used when the CALL instruction used to switch to a new procedure uses a call gate with a non-zero word count to access the new procedure. Here, the source operand for the RET instruction must specify the same number of bytes as is specified in the word count field of the call gate. The RET instruction can be used to execute three different types of returns: *Near return—A return to a calling procedure within the current code segment (the segment currently pointed to by the CS register), sometimes referred to as an intrasegment return. *Far return—A return to a calling procedure located in a different segment than the current code segment, sometimes referred to as an intersegment return. *Inter-privilege-level far return—A far return to a different privilege level than that of the currently executing program or procedure.
描述:
这条指令将程序转移到栈顶的返回地址处执行,而栈顶的这个地址通常是call指令压入的,也就是说这条指令通常是和call指令紧密相连的。 可选的源操作数用来指定在返回地址被弹出后还需要释放(或者说)弹出的字节数,默认情况下这个数目为0。这个操作数可以被用来释放传给被调用程序并且在返回后不再需要的参数。当call指令指向一个参数个数不为0的调用门时,这个操作数必须被使用并且它的值必须与调用门中的字段count field 的值相等。ret指令可以被用于以下三种情况: * 短返回:当前代码段的调用返回,pop eip; 若有参 add esp,count * 长返回:其他代码段的调用返回,pop eip,pop cs; 若有参 add esp,count * 高特权级的调用返回:1 pop eip;pop cs; 2 若有参 add esp,count; 3 pop esp;pop ss; 4 若有参 add esp,count; ;具体过程参见《自己动手编写操作系统》p74
|
一共有 31 条评论