SPRUIY2A November 2024 – March 2025 F29H850TU , F29H859TU-Q1
The Pointer Addressing with Pointer Offset type allows indirect read or write access to any location in the 32-bit memory space with the pointer address (base address register) from one of the addressing registers, A0 to A14, and an offset provided by an additional pointer (index register) in the instruction.
This structure allows for easy data array access using a variable index. An example of this can be demonstrated with a 32-bit integer array. If the eighth int in the array is needed, the element can be accessed as follows:
; Because the array is of type int, each element is 4 bytes (32 bits) long.
; So the index must be multiplied by 4 (which is the same as <<2)
; Starting parameters:
; int arr[7] = 12
; A2 = arr (base address)
; A0 = i (index) = 7 (the eigth int in the array)
LD.32 D0,*(A2+A0<<2) ; D0 = arr + (7<<2 byte offset)
; Result:
; D0 = 12The offset provided from the register and shift is added to the base register using a full 32-bit unsigned ADD operation. If the value overflows, the value wraps around.
This allows for negative index values to wrap around:
; Starting parameters:
; A2 = arr = 8 = 0x0000 0008 (base address at 8th byte in memory space)
; A0 = i = -1 = 0xFFFF FFFF (index at -1)
*(A2+A0) = 8 + (-1) = 7th byte in memory space