Properties
of the
array and
list
data structures
- The
array
data structure is
designed
for
speed
(sacrificing
flexibility):
- Every
array element in
an array can
be
access
immediately
-
Increasing the
size of an
array is
difficult or even
impossible
|
- The
linked list
data structure is
designed
for
flexibility
(sacrificing
speed):
- Inserting
(= increasing the
size) into a
linked list is
easy
- Accessing
a list element
requires
traversing (= take time !)
the list
|
- Accessing
data stored
in
a data structure:
- How to
access data stored in a
data structure
depends on the
structure/organization of the
data structure
|
|
Review:
how to
accessing a
simple variable
inside data structures
- A
label is used
to
mark
the
start of
a data structure
(called the
base address)
- A
simple variable
inside
a data structure
is
located
a certain number of bytes
after the
start location:
- The
distance from the
start of
the data structure is called:  
- The address of
simple variable
inside
a data structure is
computed as
follows:
address of var in data stru = base address + offset of var
|
|
(1) How to find the
base address of an
array
- Suppose an
array A
is defined as:
A: .skip N // for any data type of array !
|
- The label A is
equal
(is a symbolic constant) to the
base address of
the array !
- We can obtain the
base address of
array A
into
a register rN
using the
movw + movt instructions:
// Move the base address of array A into register rN
movw rN, #lower16:A
movt rN, #upper16:A
|
|
(2) How to find the
offset of the
ith array element
- The
offset of
the
array element A[i]
=
number bytes
between
the base address and
A[i]:
- Notice:
- There are
i
array elements
between
the base address and
A[i]
-
Each
array elements
has the
same
number of bytes
|
|
(2) How to find the
offset of the
ith array element
- The
offset of
the
array element A[i]
=
i
×
sizeof(1 array elem):
- Because:
- There are
i
array elements
between
the base address and
A[i]
-
Each
array elements
has
sizeof(1 array elem)
bytes
|
|
The load instructions of ARM
used to
access array elements
Recall:
We will learn to use the
more advanced
load instruction formats
now to
access
array variables
❮
❯