User Guide
82 General-Purpose Programming
AMD64 Technology 24592—Rev. 3.15—November 2009
The three types of RET are:
• Near Return—Transfers control back to the calling procedure within the current code segment.
• Far Return—Transfers control back to the calling procedure outside the current code segment.
• Interprivilege-Level Far Return—A far return that changes privilege levels.
All of the RET instruction types can be used with an immediate operand indicating the number of
parameter bytes present on the stack. These parameters are released from the stack—that is, the stack
pointer is adjusted by the value of the immediate operand—but the parameter bytes are not actually
popped off of the stack (i.e., read into a register or memory location).
Near Return. When a near RET is executed, the calling procedure’s return offset is popped off of the
stack and into the rIP register. Execution begins from the newly-loaded offset. If an immediate operand
is included with the RET instruction, the stack pointer is adjusted by the number of bytes indicated.
Figure 3-13 shows the stack pointer before (old rSP value) and after (new rSP value) the RET. The
stack segment (SS) is not changed.
Figure 3-13. Procedure Stack, Near Return
Far Return, Same Privilege. A far RET changes t he code segment, so the full return pointer is
popped off the stack and into the CS and rIP registers. Execution begins from the newly-loaded
segment and offset. If an immediate operand is included with the RET instruction, the stack pointer is
adjusted by the number of bytes indicated. Figure 3-14 on page 83 shows the stack pointer before (old
rSP value) and after (new rSP value) the RET. The stack segment (SS) is not changed.
513-178.eps
Procedure
Stack
Old rSPReturn rIP
New rSP
Parameters
. . .