Arrays Flashcards

1
Q

steps to access specific element in 1d array

A
  1. byte offset = index * element size

2. address = base address + byte offset

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

retrieve the 4th element (index = 3) off an array of word sized values stored in memory at the address in R4

A

LDR R5, =3

LDR R6, [R4, R5, LSL #2]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why use LSL #2 when working with word sized values

A

equivalent to multiplying register by 4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

how can 2D arrays be mapped in memory

A

each row in 2D array is mapped as sequential 1D arrays

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

steps to access 2D array elements

A
  1. index = (row * row size) + col
  2. byte offset = index * element size
  3. address = base address + offset
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A

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)}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly