pTAL Conversion Guide

Pointers
pTAL Conversion Guide527302-002
10-28
Pointer Arithmetic
If you increment or decrement a pointer in pTAL, the semantics are the same as those
of TAL. That is, the number that you add to a byte address such as a BADDR address
is the number of bytes to advance the pointer. Similarly, the number that you add to a
word address such as a WADDR is the number of 16-bit words to advance the pointer,
not the number of 32-bit words.
If you step a byte address such as a BADDR address, the number you specify is
added directly to the address already in the pointer; however, if you step a word
address, such as a WADDR address, pTAL increments the address by two times the
number you specify because all addresses on native architecture are byte addresses.
These are the only stepping operations defined in which one operand to a binary
operator is an address type and the other is not an address type.
Example 10-9. Stepping Pointers Using Arithmetic (pTAL) (page 1 of 2)
Invalid:
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
@sp := @sp '*' 2; ! ERROR: multiplication is invalid on
! addresses
@sp := @sp - 4; ! ERROR: unsigned arithmetic is required
! in 16-bit operations
@sp := 4 '-' @sp; ! ERROR: address must be left of
! subtraction operator, integer to right
END;
PROC p2;
BEGIN
STRING .EXT s[0:79];
STRING .EXT sp;
@sp := @sp '-' 2; ! ERROR: signed arithmetic is required
! on EXTADDRs
END;