3-608
INSTRUCTION SET REFERENCE
RETReturn from Procedure
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 returnA 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 returnA 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 returnA far return to a different privilege level than that of the
currently executing program or procedure.
The inter-privilege-level return type can only be executed in protected mode. Refer to Section
4.3., Calling Procedures Using CALL and RET in Chapter 4, Procedure Calls, Interrupts, and
Exceptions of the Intel Architecture Software Developers Manual, Volume 1, for detailed infor-
mation on near, far, and inter-privilege-level returns.
When executing a near return, the processor pops the return instruction pointer (offset) from the
top of the stack into the EIP register and begins program execution at the new instruction pointer.
The CS register is unchanged.
When executing a far return, the processor pops the return instruction pointer from the top of the
stack into the EIP register, then pops the segment selector from the top of the stack into the CS
register. The processor then begins program execution in the new code segment at the new
instruction pointer.
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