Page 51 - ARM 64 Bit Assembly Language
P. 51
GNU assembly syntax 35
Listing 2.2 “Hello World” program in AArch64 assembly.
1 .section .rodata // Read-only data section
2 mesg: .asciz "Hello World\n" // Define null-terminated string
3
4 .text // Text section
5 .global main
6 /*
7 * Prints "Hello World\n" and returns 0.
8 */
9 main: stp x29, x30, [sp, #-16]!
10
11 // printf("Hello World\n")
12 adr x0, mesg
13 bl printf
14
15 // return 0
16 mov w0, #0
17 ldp x29, x30, [sp], #16
18 ret
19 .size main,(. - main)
2.1.3 Directives
Directives are used mainly to define symbols, allocate storage, and control the behavior of
the assembler. Directives allow the programmer to control how the assembler does its job.
The GNU assembler has many directives, but assembly programmers typically need to know
only a few of them. All assembler directives begin with a period ‘.’ which is followed by a se-
quence of letters, usually in lower case. Listing 2.2 uses the .section, .rodata, .asciz,
.text,and .global directives. The most commonly used directives are discussed later in
this chapter. There are many other directives available in the GNU Assembler which are not
covered here. Complete documentation is available on-line as part of the GNU Binutils pack-
age.
2.1.4 Assembly instructions
Assembly instructions are the program statements that will be executed on the CPU. Most in-
structions cause the CPU to perform one low-level operation. In most assembly languages,
operations can be divided into a few major types. Some instructions move data from one lo-
cation to another. Others perform addition, subtraction, and other computational operations.
Another class of instructions are used to perform comparisons, and control which part of the