NonStop S-Series Server Description Manual (G06.24+)
TNS Execution Modes
HP NonStop S-Series Server Description Manual—520331-003
6-48
Passing Parameters to a Called Procedure
Passing Parameters to a Called Procedure
Parameters are passed to a procedure in the top-of-stack area (memory stack).
Naturally, there must be coordination between the caller and the called procedure
when passing parameters. The caller must know the order in which a procedure
expects parameters, and whether a parameter is to be an actual operand (called a
value parameter) or an address pointer (called a reference parameter).
Before the caller invokes a procedure, the parameters are prepared in the register
stack. The actual operands (for value parameters) and the addresses of operands (for
reference parameters) are loaded into the register stack in the order required by the
procedure being called. The address of a reference parameter is obtained by the
execution of a LADR (load address) instruction. The parameters that have been
prepared in the register stack are loaded on the top of the memory stack by executing
a PUSH instruction (which increments the S register accordingly).
The example shown in Figure 6-27 illustrates the instructions used to prepare the top
of the memory stack area for parameter passing. The TAL procedure being called is of
the form:
PROC b (p1,p2);
INT p1,.p2;
Parameter “p1” is a value parameter; therefore, the procedure expects an actual value
to be passed. Parameter “p2” is a reference parameter, and, therefore, the procedure
expects the G-relative address of a variable to be passed.
The call being made from procedure A is:
CALL b (j,i);
The instructions to pass these two parameters are:
LOAD L +002
LADR L +001
PUSH 711
The LOAD instruction puts the contents of the variable “j” (the value 5) on the top of the
register stack. (This is the parameter passed as “p1”, a value parameter, to procedure
B.)
The LADR instruction calculates the G-relative address of the variable “i” and puts the
address on the top of the register stack. (This is the parameter passed as “p2”, a
reference parameter, to procedure B.)
The PUSH instruction places the two parameters from the register stack on the top of
the memory stack and increments the S register setting by 2.