SPRUIY2 November 2024 F29H850TU , F29H859TU-Q1
The Pointer Addressing with #Immediate Increment/Decrement type allows indirect read or write access to any location in the 32-bit memory space with the pointer address from one of the addressing registers, A0 to A14, and a pre or post increment or decrement of the register is applied using the value located in an additional pointer register.
One of the addressing modes in this type, "*(Ax+#u7imm)++Ak", allows for a pointer increment/decrement along with an offset. This is useful in code where values are accessed close to a variable index. An example of this can be seen in the C and resultant assembly code:
C code:
For (i=0; i<N; i++)
{
ArrayY[i] = ArrayX[i] + ArrayX[i+1];
ArrayY[i+1] = ArrayX[i] - ArrayX[i+1];
}
Resultant assembly code:
; Initialize ArrayX and ArrayY Pointers and i:
MV A0,#4 ; A0 = i = 4 = increment step size
MV A2,#ArrayX ; A2 = ArrayX base address
MV A3,#ArrayY ; A3 = ArrayY base address
...
; This code is repeated N times:
LD.32 D0,*(A2 + #0) ; D0 = ArrayX[i]
||LD.32 D1,*(A2 + #1*4)++A0 ; D1 = ArrayX[i+1], A2 = A2 + A0
ADD D2,D1,D0 ; D2 = ArrayX[i] + ArrayX[i+1];
||SUB D3,D1,D0 ; D3 = ArrayX[i] - ArrayX[i+1];
ST.32 *(A3 + #0),D2 ; ArrayY[i] = D2
ST.32 *(A3 + #1*4)++A0 ; ArrayY[i+1] = D3, A3 = A3 + A0
The increment offset size provided from the #Immediate value and is added to the base register using a full 32-bit unsigned ADD operation. If the value overflows, the value wraps around.
This wrap around can be used to implement a decrementing index. For example:
; 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