4-23
PROCEDURE CALLS, INTERRUPTS, AND EXCEPTIONS
When procedure B calls procedure C, the ENTER instruction creates a new display for proce-
dure C (refer to Figure 4-10). The first doubleword holds a copy of the last value in procedure
Bs EBP register. This is used by the LEAVE instruction to restore procedure Bs stack frame.
The second and third doublewords are copies of the two stack frame pointers in procedure As
display. If procedure C were at the next deeper lexical level from procedure B, a fourth double-
word would be copied, which would be the stack frame pointer to procedure Bs local variables.
Note that procedure B and procedure C are at the same level, so procedure C is not intended to
access procedure Bs 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 proce-
dure C either on the stack or through variables global to both procedures (that is, variables in the
scope of both procedures).
Figure 4-9. Stack Frame after Entering Procedure B
EBP
Display
Old EBP
ESP
Mains EBP
Dynamic
Storage
Procedure As EBP
Mains EBP
Mains EBP
Procedure As EBP
Procedure Bs EBP
Mains EBP
Procedure As EBP