Page 95 - ARM 64 Bit Assembly Language
P. 95
80 Chapter 3
3.6 Chapter summary
The AArch64 Instruction Set Architecture, known as A64, includes 32 general-purpose regis-
ters and a four basic instruction types. This chapter explained the instructions used for
• moving data between memory and registers, and
• branching and calling subroutines.
The load and store operations are used to move data between memory and registers. The basic
load and store operations, ldr and str, have a very powerful set of addressing modes. The
assembler provides pseudo-instructions for loading addresses and loading immediate values.
The AArch64 processor provides both conditional and unconditional branch instructions. The
b instruction can be used to create loops and to create if-then-else constructs and other types
of control-flow. The bl instruction is used to call subroutines (functions). It sets the regis-
ter x30 to the pc of the next instruction before branching to the subroutine. At the end of the
called subroutine, the programmer can use the ret instruction to copy register x30 back to the
pc, thereby resuming the calling function at its next instruction.
Exercises
3.1. Which registers hold the stack pointer, return address, and program counter?
3.2. Which is more efficient for loading a constant value, the ldr pseudo-instruction, or the
mov instruction? Explain.
3.3. The str/ldr and stp/ldp instructions include an optional ‘!’ after the address regis-
ter. What does it do?
3.4. The following C statement declares an array of four integers, and initializes their val-
ues to 7, 3, 21, and 10, in that order.
int nums[]={7,3,21,10};
a. Write the equivalent in GNU ARM assembly.
b. Write the ARM assembly instructions to load all four numbers into registers w3,
w5, w6,and w9, respectively, using:
i. two ldp instructions, and
ii. four ldr instructions.
3.5. What is the difference between a memory location and a CPU register?
3.6. How many registers are provided by the ARM Instruction Set Architecture?
3.7. Assume that x is an array of integers. Convert the following C statements into ARM
assembly language.
a. x[8] = 100;
b. x[10] = x[0];