pTAL Conversion Guide

Pointers
pTAL Conversion Guide527302-002
10-27
Pointer Arithmetic
Stepping Pointers Using Arithmetic (pTAL)
The second group of expressions in Table 10-8 on page 10-25 uses arithmetic
operations to adjust an address. The arithmetic operations defined for pointers in pTAL
support most uses of pointers in existing TAL programs. The following considerations
apply to pTAL:
You can add an integer to any address type except a PROCADDR. The address
can be on the left side of the operator and the integer on the right, or the address
can be on the right side of the operator and the integer on the left:
INT .p;
@p := @p '+' 4; ! OK: increment WADDR pointer by four
! 16-bit words
@p := 4 '+' @p; ! OK: increment WADDR pointer by four
! 16-bit words
You can subtract an integer value from any address type except a PROCADDR.
The address type item must be on the left side of the subtraction operator, and the
integer on the right:
INT .p;
@p := @p '-' 4; ! OK: decrement WADDR pointer by four
! 16-bit words
@p := 4 '-' @p; ! ERROR: address must be on right,
! integer on left
You must use signed operators for operations on EXTADDRs and unsigned
operators for all other address types.
INT .p;
INT .EXT e;
@p := @p '-' 4; ! OK: unsigned arithmetic on WADDRs
@p := 4 '+' @p; ! OK: unsigned arithmetic on WADDRs
@e := @e + 8; ! OK: signed arithmetic on EXTADDRs
INT .pa := @a; ! Pointer to first word of a
STRING .pb := @b; ! Pointer to first byte of b
INT .ps := @s; ! Pointer to first element of s
PROC p;
BEGIN
@pa := @pa[2]; ! Increment pa to third word of a
@pb := @pb[2]; ! Increment pb to third byte of b
@ps := @ps[2]; ! Increment ps to third element of s
END;
Example 10-8. Stepping Pointers Using Indexing (pTAL) (page 2 of 2)