NonStop S-Series Server Description Manual (G06.24+)
TNS Execution Modes
HP NonStop S-Series Server Description Manual—520331-003
6-40
Overview of Procedure Call and Exit
Overview of Procedure Call and Exit
Procedures are invoked using procedure call instructions—PCAL to a procedure 
within the same code segment, XCAL to a procedure in some other code segment, or 
DPCL to an indirectly specified target procedure. An example of a procedure call and 
exit is shown in Figure 6-23. This example assumes the called procedure is in the 
same segment as the caller, UC.2; therefore, the PCAL instruction is used.
The beginning action of either of these instructions (PCAL, XCAL, or DPCL) is to save 
the caller’s environment. A procedure’s environment is the code and data that it is 
currently using.  For code, the environment specification needs to include complete 
segment identification (which code or library space, and which segment within that 
space). For data, the environment is its stack frame. Both aspects of environment 
preservation are accomplished by the use of a three-word stack marker to separate 
stack frames within the memory stack. The data inside the marker provides the 
restoration information, specifically the address of the instruction following the call 
(P register value), the caller’s Environment register setting, and the L register setting of 
the caller. The saved version of the Environment register is slightly modified to include 
a space ID index; note the space ID index value of 2 in the example.
Once the caller’s environment is preserved, a new environment is set up for the called 
procedure. First, the L register is set to the value in the adjusted S register. This 
defines the base of a new stack frame for the called procedure’s local data area.
The call instruction (PCAL in this case) then accesses the entry in the PEP (procedure 
entry point) table corresponding to the procedure being called. The called procedure’s 
callability attributes are checked first, then the address in the PEP entry is placed in the 
P register so that the next instruction executed is the one at the called procedure’s 
entry point. The called procedure now executes, using its own stack frame on the data 
stack for its local data.
The last instruction that a procedure executes is an EXIT instruction. The EXIT 
instruction returns control to the caller. In brief overview, this return of control is 
accomplished by restoring the caller’s L and S register settings and by setting into the 
P register the return address (that is, the address of the instruction following the 
original call instruction). The caller’s Environment register setting also is restored—
except for the Condition Code (CC) and Register Pointer (RP) fields, which are left as 
is; that is because these fields in the stack marker copy of the Environment register 
were used to save the space ID index.
The next two topics consider in greater detail the operations of the PCAL and EXIT 
instructions. The special case of calling external procedures using the XCAL 
instruction is described later in this section.










