
EXTENDED INSTRUCTION SET
The Formal Definition Of The ENTER Instruction For All Cases Is Given By The Following Listing. LEVEL Denotes The Value Of The Second Operand.
Push BP
Set a temporary value FRAME_PTR : ~ SP
If LEVEL> 0 then
Repeat (LEVEL
BP:~
Push the word pOinted to by BP
End repeat
Push FRAME_PTR
End If
BP : ~ FRAME_PTR
SP : ~ SP - first operand.
Figure 4-1. Formal Definition of the ENTER Instruction
The main procedure (with other procedures nested within) operates at the highest lexical level, level 1. The first procedure it calls operates at the next deeper lexical level, level 2. A level 2 procedure can access the variables of the main program which are at fixed locations specified by the compiler. In the case of levell, ENTER allocates only the requested dynamic storage on the stack because there is no previous display to copy.
A program operating at a higher lexical level calling a program at a lower lexical level requires that the called procedure should have access to the variables of the calling program. ENTER provides this access through a display that provides addressability to the calling program's stack frame.
A procedure calling another procedure at the same lexical level implies that they are parallel proce- dures and that the called procedure should not have access to the variables of the calling procedure. In this case, ENTER copies only that portion 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 procedure's stack frame.
ENTER treats a reentrant procedure as a procedure calling another procedure at the same lexical level. In this case, each succeeding iteration of the reentrant procedure can address only its own varia- bles and the variables of the calling procedures at higher lexical levels. A reentrant procedure can always 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, ENTER makes sure that procedures access only those variables of higher lexical levels, not those at parallel lexical levels (see figure
1.MAIN PROGRAM has variables at fixed locations.
2.PROCEDURE A can access only the fixed 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.