Intel 80286 Computer Accessories User Manual


 
EXTENDED INSTRUCTION SET
15
OLDBP
BPM
BPM
BPM
BPA
BP_
BPA
BPM
BPA
BPB
SP_
0
I
DISPLAY
)
DYNAMIC
STORAGE
Figure 4-2d. Stack Frame
for
Procedure C
at
Level 3 Called from B
G30108
After PROCEDURE A calls PROCEDURE
B,
ENTER creates a
new
display for PROCEDURE B
with the first word pointing to the previous value of BP, the second word pointing to the value of BP
for MAIN, and the third word pointing
to
the value of BP for A and the last word pointing to the
current
BP.
B can access variables
in
A and MAIN
by
fetching from the display the base addresses of
the respective dynamic storage areas.
See figure 4-2c.
After PROCEDURE B calls PROCEDURE C,
ENTER
creates a
new
display for PROCEDURE C
with the first word pointing to the previous value of BP, the second word pointing to the value of BP
for MAIN, and the third word pointing
to
the BP value for A and the third word pointing to the current
value of BP. Because PROCEDURE B and PROCEDURE C have the same lexical level,
PROCE-
DURE
C
is
not allowed access
to
variables in B and therefore does not receive a pointer to the begin-
ning of PROCEDURE B's stack frame. See figure 4-2d.
LEAVE
(Leave Procedure) reverses the action of the previous ENTER instruction. The LEAVE
instruction does not include any operands.
Example: LEAVE. First, LEAVE copies
BP
to
SP
to
release all stack space allocated to the proce-
dure
by
the most recent
ENTER
instruction. Next, LEAVE
pops
the old value of
BP
from
the stack. A
subs~quent
RET instruction can then remove anYl1rguments that were pushed
on
the stack
by
the calling program for use by the called procedure.
4-6