Arrays Flashcards
steps to access specific element in 1d array
- byte offset = index * element size
2. address = base address + byte offset
retrieve the 4th element (index = 3) off an array of word sized values stored in memory at the address in R4
LDR R5, =3
LDR R6, [R4, R5, LSL #2]
Why use LSL #2 when working with word sized values
equivalent to multiplying register by 4
how can 2D arrays be mapped in memory
each row in 2D array is mapped as sequential 1D arrays
steps to access 2D array elements
- index = (row * row size) + col
- byte offset = index * element size
- address = base address + offset
retrieve the element from index [3][2] in an array of words with 6 rows and 8 columns
address starts at R4, no of rows in R5. no of cols in R6
LDR R1, =3
LDR R2, =2
MUL R7, R1, R6 @index = row by row size
ADD R7, R7, R2 @index += col
LDR R0, [R4, R7, LSL #2} @elem = word[array + (index*elemSize)}