4-20
PROCEDURE CALLS, INTERRUPTS, AND EXCEPTIONS
A procedure which calls another procedure at the same lexical level should not give access to
its variables. In this case, the ENTER instruction copies only that part of the display from the
calling procedure which refers to previously nested procedures operating at higher lexical levels.
The new stack frame does not include the pointer for addressing the calling procedures stack
frame.
The ENTER instruction treats a re-entrant procedure as a call to a procedure at the same lexical
level. In this case, each succeeding iteration of the re-entrant procedure can address only its own
variables and the variables of the procedures within which it is nested. A re-entrant procedure
always can address its own variables; it does not require pointers to the stack frames of previous
iterations.
By copying only the stack frame pointers of procedures at higher lexical levels, the ENTER
instruction makes certain that procedures access only those variables of higher lexical levels, not
those at parallel lexical levels (refer to Figure 4-6).
Block-structured languages can use the lexical levels defined by ENTER to control access to the
variables of nested procedures. In Figure 4-6, for example, if procedure A calls procedure B
which, in turn, calls procedure C, then procedure C will have access to the variables of the
MAIN procedure and procedure A, but not those of procedure B because they are at the same
lexical level. The following definition describes the access to variables for the nested procedures
in Figure 4-6.
1.MAIN has variables at fixed locations.
2.Procedure A can access only the variables of MAIN.
3.Procedure B can access only the variables of procedure A and MAIN. Procedure B cannot
access the variables of procedure C or procedure D.
4.Procedure C can access only the variables of procedure A and MAIN. procedure C cannot
access the variables of procedure B or procedure D.
5.Procedure D can access the variables of procedure C, procedure A, and MAIN. Procedure
D cannot access the variables of procedure B.
Figure 4-6. Nested Procedures
Main (Lexical Level 1)
Procedure A (Lexical Level 2)
Procedure B (Lexical Level 3)
Procedure C (Lexical Level 3)
Procedure D (Lexical Level 4)