ZHCUCH3A November 2024 – March 2025 F29H850TU , F29H859TU-Q1
借助“具有指针偏移的指针寻址”类型,可以对 32 位存储器空间中的任何位置进行间接读写,其中指针地址(基址寄存器)来自寻址寄存器之一 A0 到 A14,以及由指令中的附加指针(索引寄存器)提供的偏移。
利用该结构,可以使用变量索引轻松访问数据数组。这方面的一个示例可以通过 32 位整数组来演示。如果需要数组中的第八个 int,则可以按如下方式访问该元素:
; 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 = 12由寄存器和移位提供的偏移使用完整的 32 位无符号加法运算添加到基址寄存器中。如果值溢出,该值将绕回。
这样就可以绕回负索引值:
; 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