Page 164 - ARM 64 Bit Assembly Language
P. 164
150 Chapter 5
the programmer, and failure to apply structured programming techniques will result in code
that is difficult to understand, debug, and maintain.
Subroutines provide a way to split programs into smaller parts, each of which can be written
and debugged individually. This allows large projects to be divided among team members.
In assembly language, defining and using subroutines is not as easy as in higher level lan-
guages. However, the benefits far outweigh the costs. The C library provides a large number
of functions. These can be accessed by an assembly program as long as it is linked with the C
standard library.
Assembly provides the mechanisms to access aggregate data types. Arrays can be accessed
using various addressing modes on the AArch64 processor. The Pre-indexing, and post-
indexing modes allow array elements to be accessed using pointers, with the pointers being
incremented after each element access. Fields in structured data records can be accessed us-
ing immediate offset addressing mode. The rich set of addressing modes available on the
AArch64 processor allow the programmer to use aggregate data types more efficiently than
on most processors.
Exercises
5.1. What does it mean for a register to be volatile? Which AArch64 registers are consid-
ered volatile according to the AArch64 function calling convention?
5.2. Fully explain the differences between static variables and automatic variables.
5.3. In AArch64 Assembly language, write a function that is equivalent to the following C
function.
1 int max(int a, int b)
2 {
3 if( a > b )
4 return a;
5 return b;
6 }
5.4. What are the two places where an automatic variable can be stored?
5.5. You are writing a function and you decided to use registers x19 and x20 within the
function. Your function will not call any other functions. It is self-contained. Mod-
ify the following skeleton structure to ensure that x19 and x20 can be used within the
function and are restored to comply with the AArch64 standards, but without unneces-
sary memory accesses.
1 .text
2 .type myfunc, %function
3 myfunc: