Hi,
I have forgotten….. The instruction you use in given form has offset of 5 bits long, represents number of bytes and you use words.
M[RB, #OFFS5] ⇒RD
So max offset is 32 bytes or 16 words.
Look at this simple example of writing the Array of 256 words addressed by variable index.
Note that R0 is always 0.
XGATE_DATA: SECTION
; put your variables here
ALIGN 2
Arr DS.W 256
Index DS.W 1
XGATE_CODE: SECTION
; interrupt handler for the software trigger 0
ALIGN 2
SoftwareTrigger0_Handler:
; load index with value
LDW R2, Index ; Addr to Index
LDL R3, #17 ;
STW R3, (R2,R0) ; Save Index value
;-------------------------- Write Arr[5] = 0x1234
LDW R3, Index ; Get address of Index
; R3 = get address of index
LDW R2, (R3, R0) ; R2 = Index
LSL R2, #$1 ; Calculate Index in bytes; R2 = Index*2 data set is size of word
; Get position of Arr[Index]
LDW R3, Arr ; Base address of Addr
ADD R4, R2,R3 ; Calculate Arr[Index] position = Arr + Index*2
LDW R3, #$1234
STW R3, (R4, R0) ; Write Arr[Index] = $1234
Note, in the memory window you will see Arr[0..512] (even we defined Arr DS.W 256) so writing word to arr index 17 will in reality write word to Arr[34] and arr[35] in memory window.
Note that similar is read from the array.
If you want to use instruction with #OFF5 then you can make something like addressing 2dimensional array of words which has elements [x,16]. But I see this as little bit complicated.
Best regards,
L.