|
Remember that I said in this webpage ( click here) that:
|
This comment applies whenever you access a data structure such as an array (and later: a linked list)
|
|
base address of the array + offset to the array element
Graphically explained:
|
The offset is equal to the number of bytes between:
|
There are i array elements between the start of the array and the start of array element A[i]:
We know the data type of the array, and therefore, we also know the size (= number of bytes) of each array element.
Because each array element has the same data type (and therefore each array element occupies the same number of bytes), the offset to the array element A[i] is equal to:
offset to A[i] = i × size(one array element) |
start address of array element A[i] = base address of array + i × size(one array element) |
Graphically explained:
Once you have computed the start address of the array element, you can then:
|
We will learn this advance format of the load and store instruction next before we write assembler code to access arrays.