User's Manual

EXTENDED INSTRUCTION SET
MAIN PROGRAM (LEXICAL LEVEL 1)
PROCEDURE A (LEXICAL LEVEL
2)
PROCEDURE B (LEXICAL LEVEL
3)
PROCEDURE C (LEXICAL LEVEL
3)
PROCEDURE D (LEXICAL LEVEL
4)
Figure 4-2. Variable
Access
in Nested Procedures
15
0
BPFOR
MAIN -
OLDBP
BPM'
SP_
'BPM - BP VALUE FOR MAIN
} DISPLAY
DYNAMIC
STORAGE
Figure 4-2a.
Stack
Frame
jor
MAiN
at
Levei 1
G30108
G30108
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.
ENTER
at
the beginning of the MAIN PROGRAM creates dynami\; sturage space fuf MAIN but
copies
no
pointers. The first and only word in the display points
to
itself because there
is
no
previous
value for LEAVE
to
return to
BP.
See figure
4~2a.
After
MAIN
calls PROCEDURE
A,
ENTER
creates a
new
display for PROCEDURE A with the
first word pointing
to
the previous value of BP (BPM for LEAVE to return
to
the MAIN stack frame)
and the second word pointing to the current value of
BP.
Procedure A can access variables in
MAIN
since
MAIN
is
at
level
1.
Therefore the base
for
the dynamic storage for MAIN
is
at
[BP-2j.
All
dynamic variables for
MAIN
will
be
at
a fixed offset from this value. See figure
4-2b.
4-4