Download Turtle: Innovative Software for the Learning of

Transcript
73
The only other change is that the procedure here ends with “PLRJ” rather than “ENDP”
– procedure termination has to involve a different command if the machine is to continue
execution from the return location stored on the Program Stack (the effect of “PLRJ”)
rather than looking for the return location on the Procedure Return Stack.49
6.7.2 Doing Without the Heap Control Stack
Managing Heap space without the Heap Control Stack is a relatively complex business,
requiring that the relevant Heap pointers be passed and calculated on the Program Stack
rather than being controlled through a specially tailored mechanism. The Heap Top
Pointer is retained as a single register (rather than as the top of a stack), and each
procedure still has its own Procedure Heap Pointer, keeping track of the relevant Heap
Base address.
But now these must be maintained explicitly, using the instructions
“LDHT” and “STHT”, which respectively load and store the current Heap Top Pointer,
and “LDHB” and “STHB”, which load and store the Procedure Heap (Base) Pointer for
a specified procedure:
Informal description of
command behaviour
Assembler
mnemonic
Decimal
code
Hex
code
load Heap Top Pointer
LDHT
226
$E2
store Heap Top Pointer
STHT
227
$E3
load Heap Base Pointer
LDHB
228
$E4
store Heap Base Pointer
STHB
229
$E5
This Heap maintenance is done as follows: (Some code line numbers are changed, but
for convenient comparison, the previous numbering is shown, in brackets.)
49
For the sake of simplicity the procedure call still involves “PROC”, which adjusts the Procedure
Return Stack, so that stack is in fact maintained. However it is not used – “PLRJ” removes the return
location from this stack (to prevent overflow) but just discards it, using the Program Stack value
instead.