Page 156 - ARM 64 Bit Assembly Language
P. 156
142 Chapter 5
41 ldp x29, x30, [sp], #16
42 ret
43 .size main, (. - main)
5.5 Aggregate data types
An aggregate data item can be referenced as a single entity, and yet consists of more than one
piece of data. Aggregate data types are used to keep related data together, so that the program-
mer’s job becomes easier. Some examples of aggregate data are arrays, structures or records,
and objects. In most programming languages, aggregate data types can be defined to create
higher-level structures. Most high-level languages allow aggregates to be composed of basic
types as well as other aggregates. Proper use of structured data helps to make programs less
complicated and easier to understand and maintain.
In high-level languages, there are several benefits to using aggregates. Aggregates make the
relationships between data clear, and allow the programmer to perform operations on blocks
of data. Aggregates also make passing parameters to functions simpler and easier to read.
5.5.1 Arrays
The most common aggregate data type is an array. An array contains zero or more values of
the same data type, such as characters, integers, floating point numbers, or fixed point num-
bers. An array may also be contain values of another aggregate data type. Every element in an
array must have the same type. Each data item in an array can be accessed by its array index.
Listing 5.34 shows how an array can be allocated and initialized in C. Listing 5.35 shows the
equivalent code in AArch64 assembly. Note that in this case, the scaled register offset ad-
dressing mode was used to access each element in the array. This mode is often convenient
when the size of each element in the array is an integer power of 2. If that is not the case, then
it may be necessary to use a different addressing mode. An example of this will be given later
in Section 5.5.3.
5.5.2 Structured data
The second common aggregate data type is implemented as the struct in C or the record in
Pascal. It is commonly referred to as a structured data type or a record. This data type can
contain multiple fields. The individual fields in the structured data are referred to as structured
data elements or simply elements. In most high-level languages, each element of a struc-
tured data type may be one of the base types, an array type, or another structured data type.