Intel 64 and IA-32 Architectures Software Developers Manual Volume 1, Basic Architecture

Vol. 1 6-5
PROCEDURE CALLS, INTERRUPTS, AND EXCEPTIONS
6.2.5 Stack Behavior in 64-Bit Mode
In 64-bit mode, address calculations that reference SS segments are treated as if the
segment base is zero. Fields (base, limit, and attribute) in segment descriptor regis-
ters are ignored. SS DPL is modified such that it is always equal to CPL. This will be
true even if it is the only field in the SS descriptor that is modified.
Registers E(SP), E(IP) and E(BP) are promoted to 64-bits and are re-named RSP, RIP,
and RBP respectively. Some forms of segment load instructions are invalid (for
example, LDS, POP ES).
PUSH/POP instructions increment/decrement the stack using a 64-bit width. When
the contents of a segment register is pushed onto 64-bit stack, the pointer is auto-
matically aligned to 64 bits (as with a stack that has a 32-bit width).
6.3 CALLING PROCEDURES USING CALL AND RET
The CALL instruction allows control transfers to procedures within the current code
segment (near call) and in a different code segment (far call). Near calls usually
provide access to local procedures within the currently running program or task. Far
calls are usually used to access operating system procedures or procedures in a
different task. See “CALL—Call Procedure” in Chapter 3, “Instruction Set Reference,
A-M, of the Intel® 64 and IA-32 Architectures Software Developer’s Manual,
Volume 2A, for a detailed description of the CALL instruction.
The RET instruction also allows near and far returns to match the near and far
versions of the CALL instruction. In addition, the RET instruction allows a program to
increment the stack pointer on a return to release parameters from the stack. The
number of bytes released from the stack is determined by an optional argument (n)
to the RET instruction. See “RET—Return from Procedure” in Chapter 4, “Instruction
Set Reference, N-Z,” of the Intel® 64 and IA-32 Architectures Software Developer’s
Manual, Volume 2B, for a detailed description of the RET instruction.
6.3.1 Near CALL and RET Operation
When executing a near call, the processor does the following (see Figure 6-2):
1. Pushes the current value of the EIP register on the stack.
2. Loads the offset of the called procedure in the EIP register.
3. Begins execution of the called procedure.