HP 3000 III Series Manual page 178

Table of Contents

Advertisement

Machine Instructions and Stack Operations
followed each time by a stack marker.
Thus,
when the final LOAD
Q-4 occurs in preparation for the zero test, the stack appears as
shown at (N).
4-25. FIRST EXIT.
The check at
address 115 now
finds that
the
parameter
is zero.
The checked copy of the parameter is deleted
from the stack (P),
figure 4-21
and the
branch at
address 116
transfers control to address 117 (rather than 121).
As mentioned
earlier in paragraph 4-20, an assumed value of 1 is necessary
as
an
initial previous product in order to begin the mUltiplication
loops. This is accomplished by a LDI 1 instruction (address 117),
which puts a 1 on the top of the stack (Q).
Then an uncondition-
al branch at address 120 transfers control to address 126,
where
the
"1"
on the top of the stack is stored into the location re-
served for
this recursion's
answer as shown
at (R).
The next
instruction is the EXIT 1 instruction at address 127.
This caus-
es
Q
to
move back six locations
(Del ta Q
=
6)
and S five loca-
tions
(EXIT 1 deletes
one of the two
parameters),
as shown at
(S).
The return
address for the P Register is the MPYM
Q-4 in-
struction at
address 125.
This causes the parameter at Q-4 (1)
to be multiplied
by the 1 an the top
of the stack,
leaving the
answer
as the new TOS element.
Since lxl
=
1 there is no appar-
ent change from
(5)
to (T) but,
in
fact,
a multiplication
has
occurred.
4-26.
FIRST RECURSIVE EXIT.
The answer of the first mUltiplica-
tion is now stored in the location reserved for it (Q-5) as shown
at (U),
figure 4-21
by the STOR Q-S instruction at address 126.
The next instruction,
at 127,
is again the
EXIT 1
instruction
which moves back the stack as shown at (V) and returns the P Reg-
ister to the MPYM Q-4 instruction at address 125.
The parameter
for
multiplication (at Q-4) is now 2 and, therefore, the multip-
lication result at (W) is 2.
Again, this is stored back
in the
location reserved for it (Q-5) as shown at (X).
4-27. SUCCESSIVE EXITS.
After saving the result, the next EXIT 1
is encountered again, causing the Sand Q stack pointers to
move
back to the
next marker,
leaving the answer
2 on the TOS.
The
return for the P Register is again 125, the MPYM
Q-4 instruction
mUltiplies 2x3, and the following STOR Q-5 puts the answer 6 into
the reserved location as shown at (Y), figure
4-21.
Similarly,
the
last recursive exit causes the value 6 to be left on the TOS
when the last return to address 125 is made.
Then the final mul-
tiplication mUltiplies 6x4 and the last STOR Q-5 instruction puts
the answer 24 into the
location originally reserved for
the end
result FACTORIAL.
The last EXIT instruction finds the return for
the Q Register (Delta Q) pointing back to the
origin of an earl-
ier procedure and therefore, is not shown in the stack diagram at
(Z).
However, since one parameter is saved, the final answer re-
mains on the TOS as shown.
Meanwhile, the P Register returns
to
the next
instruction in the outer block
which is the STOR DB 15
instructi.on at address 133.
This saves the answer in the
global
area and a final PCAL returns control to the system.
4-48

Advertisement

Table of Contents
loading

Table of Contents