Subroutine Call And Exit - HP 3000 III Series Manual

Table of Contents

Advertisement

Machine Instructions and Stack Operations
the
P Register, while the former value of P, plue one, is stored
in the TOS as the re tur n addres s.
Howeve r, if N we re 0, it would
be assumed that the TOS
contains
the
local
label
(subroutine
starting
address).
This address, then, (made absolute) would be
loaded into the P Register, while the former
value
of
P,
plus
one,
replaces
the
label
on the TOS as the return address.
In
either case, once the P Register has its new address,
the
loca-
tion
so
indicated
will
be
fetched
and
subroutine execution
begins.
SCAL
SXIT
Code
Stack
Code
Stack
PB
P
~{{
SXIT
Return
P
--..
Pl
....
}
Segment
Transfer
Table
PB
P
seAL N
/
Subroutine
~
....
Pl
}N
/
(
---
....
....
S...........
- - - o t
j
-
I
I
I
I
I
I
I
~--------
~-------J
If N
=
0
·Store P+ 1
In
TOS
Figure 4-10.
Subroutine Call and Exit
The final instruction of the subroutine is SXIT.
At
this
time
the
return address, pushed onto the stack by SCAL,
is assumed to
be on the TOS.
It is the responsibility
of
the
subroutine
to
provide
this
condition, which normally means deleting all vari-
ables incurred by the subroutine.
The
SXIT
instruction
simply
takes
the
address
contained
in
the
TOS
and
puts it in the
P-register, thus effecting a return to the calling routine.
As a
final step, SXIT deletes the TOS, since the return address is
no
longer
needed,
and
may additionally move S back some number of
locations specified by N.
This
would
typically
be
used
for
deleting some of the parameters passed to the subroutine.
6.
PCAL, EXIT. These two instructions perform basically the same
function as
the SCAL and SXIT
inst~uctions
described above (In-
struction Commentary 5).
That is,
to call a routine and
return
from it
to the
point where
it was called.
However, since the
routines in the case of PCAL/EXIT may be external to the
current
segment,
possibly not even present in main memory, the operation
is somewhat more complex.
4-27

Advertisement

Table of Contents
loading

Table of Contents