NonStop S-Series Server Description Manual (G06.24+)
TNS Execution Modes
HP NonStop S-Series Server Description Manual—520331-003
6-52
Saving the Stack Frame on a Call
Saving the Stack Frame on a Call
When a procedure is called, a new stack frame is defined. This occurs because the
address contained in the L register advances to point above the current local area (the
caller’s local area is then inaccessible by direct addressing). Conversely, when a
procedure exits, the exiting procedure’s stack frame is deleted (and the preceding
stack frame made accessible again) because the address in the L register recedes
back to its previous setting.
This and the following topics depict an example of memory stack operations from an
initial state (that is, start of process execution) through a call to, and subsequent return
from, a procedure. The purpose of this example is to show the action of the L and S
registers as a procedure generates its local variables and prepares to call a procedure
by passing parameters, how L and S are advanced when a procedure is called, and
how L and S are restored when the return is made to the caller.
The following numbered steps refer to Figure 6-29.
1. Initial State. After the operating system has loaded a program into memory but
before the first instruction of the process executes, the following initial conditions
are present: the process’s global variables are initialized and present, and the L
and S registers are set to the address of the word just past the global area. There
are no local variables defined at this time.
2. Procedure A allocates its local variables. The first few instructions of a
procedure allocate the procedure’s local variables. As the local variables are
allocated, the S register setting increases, defining a new upper limit to the
procedure’s stack frame. Note that the L register setting does not change.
3. Procedure A prepares parameters for procedure B. In preparation for calling
the procedure B, the parameter words (two in this example) are placed on the top-
of-stack location as indicated by the S register setting. The S register setting is
increased by 2 to account for the parameters.
4. A calls B. After the parameters are loaded onto the memory stack, a procedure
call instruction is executed; this could be a PCAL (Procedure Call), XCAL (External
Procedure Call), or DPCL (Dynamic Procedure Call). Execution of the call
instruction places a three-word stack marker at the current S register setting plus 1
(just above the parameters). The L and S registers are given a new setting; they
both point to the third word of the stack marker. The new L register setting defines
the start of B’s local area. At this point, no local variables have yet been allocated
for procedure B. (Note that A’s local area, which is normally addressed relative to
the L register, is no longer addressable by the L-plus addressing mode.)
(The next topic continues this sequence.)