pTAL Guidelines for TAL Programmers
Coding Guidelines
pTAL Guidelines for TAL Programmers—527256-002
2-53
TNS Registers and Trap Handlers
TNS Registers and Trap Handlers
Guideline: Use registers in trap handlers only in programs running as TNS processes.
Do not attempt to change the values of TNS registers in a trap handler and then
resume running your program. For versions of pTAL programs that run as TNS
processes, access the values of TNS registers only to print them or to save them in a
log file.
The values of TNS registers are not meaningful in pTAL programs that run as native
processes.
Saving the P, L, and S Registers
Guideline: Do not implement state machines by saving and restoring the P, L, and S
registers.
TAL programs can implement state machines by saving the values of the P, L, and S
registers in variables. To go to the next state, the program stores in the P, L, and S
registers the saved register values. This action causes the program to branch to the
top of the state machine, where it can use a CASE statement to branch to the next
state.
This approach does not work in pTAL because the underlying native architecture
differs from that of TNS architecture. Also, you cannot store into P, L, or S because
pTAL does not support CODE statements.
Example 2-66. Saving the P, L, and S Registers (TAL Only)
PROC driver;
BEGIN
INT s = 'S';
INT l = 'L';
save_l := @l;
save_s := @s;
save_p := @state_change;
...
state_change:
CASE next_state of
BEGIN
state_1: ...
...
END;
! Cut back stack, go to next state, and branch to state
! change code:
next_state := value;
STACK save_p, save_s, save_l;
CODE( SETL; SETS; SETP ); ! Branch to code at the label
END; ! STATE_CHANGE