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

6-24 Vol. 1
PROCEDURE CALLS, INTERRUPTS, AND EXCEPTIONS
When procedure B calls procedure C, the ENTER instruction creates a new display for
procedure C (see Figure 6-10). The first doubleword holds a copy of the last value in
procedure B’s EBP register. This is used by the LEAVE instruction to restore procedure
B’s stack frame. The second and third doublewords are copies of the two stack frame
pointers in procedure A’s display. If procedure C were at the next deeper lexical level
from procedure B, a fourth doubleword would be copied, which would be the stack
frame pointer to procedure B’s local variables.
Note that procedure B and procedure C are at the same level, so procedure C is not
intended to access procedure B’s variables. This does not mean that procedure C is
completely isolated from procedure B; procedure C is called by procedure B, so the
pointer to the returning stack frame is a pointer to procedure B’s stack frame. In
addition, procedure B can pass parameters to procedure C either on the stack or
through variables global to both procedures (that is, variables in the scope of both
procedures).
Figure 6-9. Stack Frame After Entering Procedure B
EBP
Display
Old EBP
ESP
Main’s EBP
Dynamic
Storage
Procedure A’s EBP
Main’s EBP
Main’s EBP
Procedure A’s EBP
Procedure B’s EBP
Main’s EBP
Procedure A’s EBP