pTAL Conversion Guide
Pointers
pTAL Conversion Guide—527302-002
10-29
Pointer Arithmetic
Computing the Number of Bytes Between Addresses (pTAL)
The third group of expressions in Table 10-8 on page 10-25 shows how you can 
subtract one address from another to determine the number of words or bytes between 
them. The code in Example 10-10 on page 10-29 scans a string for a plus sign (+) and 
computes the number of bytes between the beginning of the string and the plus sign.
Valid:
PROC p;
BEGIN
 STRING .s[0:79];
 STRING .sp;
 ... ! Read data into STRING buffer s
 @sp := @s; ! Initialize sp to beginning of s
 ...
 @sp := @sp '+' 2; ! Skip to third byte of s
 @sp := @s '+' $LEN(s) '-' 2; ! Skip to last two bytes of s
 ! Note that @s + $LEN(s) adds
 ! 16-bit integer to
 ! WADDR value, which produces
 ! WADDR value from which
 ! 16-bit integer, 2,
 ! is subtracted
END;
PROC p2;
BEGIN
 STRING .EXT s[0:79];
 STRING .EXT sp;
 @sp := @s + 12; ! Skip to 13th byte of s
END; 
Example 10-10. Computing the Number of Bytes Between Addresses (pTAL)
PROC p;
BEGIN
 INT i;
 STRING .s[0:79];
 STRING .sp := @s; ! sp points to s
 SCAN sp UNTIL "+" -> @sp; ! Find plus sign in s
 i := @sp '-' @s; ! Compute number of bytes between
END; ! beginning of s and plus sign
Example 10-9. Stepping Pointers Using Arithmetic (pTAL) (page 2 of 2)










