pTAL Guidelines for TAL Programmers
Coding Guidelines
pTAL Guidelines for TAL Programmers—527256-002
2-27
Parameter Accesses Using Based-Address
Equivalenced Declarations, Indexing, and Pointers
Do not read values from or store values into the TNS stack marker. The stack marker
on native architecture is not compatible with the stack marker on TNS architecture.
The pTAL compiler cannot detect code that accesses the stack marker by indexing or
by storing the address of a stack marker component in a pointer, as in Example 2-25
on page 2-27. If your code uses either of these techniques, find each such occurrence
and change your code. If you run native object code that references data at locations
below the beginning of a procedure’s declared data, the results are undefined.
In TAL, a procedure can examine the stack marker to determine if it is a privileged
procedure or if the procedure that called it is privileged. pTAL cannot examine the
stack marker in this manner.
Parameter Accesses Using Based-Address Equivalenced
Declarations, Indexing, and Pointers
Guideline: Access parameters only by referencing the name of the parameter.
In TAL, you can use the techniques described in Base-Address Equivalencing on
page 2-51 to access procedure parameters.
In pTAL, you can access procedure parameters only by explicit reference to each
parameter’s name, not by an offset relative to the L register or to the beginning of a
procedure’s local data. The same guidelines previously described for accessing the
stack marker apply to accessing a procedure’s parameters.
Overflow Bit in ENV in Stack Marker
Guideline: Do not cause exceptions by setting the overflow bit in the stack-marker
copy of the ENV register.
In TAL, a procedure can set the overflow bit (bit 10) in the stack marker copy of the
ENV register—the value of the TNS processor’s ENV register in the caller’s
environment. Setting this bit causes an arithmetic overflow exception when the
procedure returns to its caller.
Example 2-25. Using Indexing and Pointers to Access Stack Marker (TAL Only)
PROC p;
BEGIN
INT .env_reg(env_layout); ! Structure pointer
INT t; ! t gives (G-rel+2) address of
! beginning of p's locals
@env_reg := @t '-' 3; ! Store address of ENV in pointer
IF env_reg.trap_enable THEN ! Test if caller had traps
BEGIN ! enabled
...
END;
END;