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

6-2 Vol. 1
PROCEDURE CALLS, INTERRUPTS, AND EXCEPTIONS
When a system sets up many stacks, only one stack—the current stack—is avail-
able at a time. The current stack is the one contained in the segment referenced by
the SS register.
The processor references the SS register automatically for all stack operations. For
example, when the ESP register is used as a memory address, it automatically points
to an address in the current stack. Also, the CALL, RET, PUSH, POP, ENTER, and
LEAVE instructions all perform operations on the current stack.
6.2.1 Setting Up a Stack
To set a stack and establish it as the current stack, the program or operating
system/executive must do the following:
1. Establish a stack segment.
2. Load the segment selector for the stack segment into the SS register using a
MOV, POP, or LSS instruction.
Figure 6-1. Stack Structure
Bottom of Stack
(Initial ESP Value)
Local Variables
for Calling
Procedure
Parameters
Passed to
Called
Procedure
Frame Boundary
EBP Register
ESP Register
Return Instruction
Top of Stack
Stack Segment
Pushes Move the
Top Of Stack to
Lower Addresses
Pops Move the
Top Of Stack to
Higher Addresses
The EBP register is
The Stack Can Be
16 or 32 Bits Wide
typically set to point
to the return
instruction pointer.
Pointer