Page 52 - ARM 64 Bit Assembly Language
P. 52
36 Chapter 2
Listing 2.3 “Hello World” assembly listing.
Line Addr Code/Data Label Instruction/Directive
--------------------------------------------------------------------------------
1 .data
2 0000 48656C6C mesg: .asciz "Hello World\n"
2 6F20576F
2 726C640A
2 00
3
4 .text
5 .global main
6 /*
7 * Prints "Hello World\n" and returns 0.
8 */
9 0000 FD7BBFA9 main: stp x29, x30, [sp, #-16]!
10
11 // printf("Hello World\n")
12 0004 00000010 adr x0, mesg
13 0008 00000094 bl printf
14
15 // return 0
16 000c 00008052 mov w0, #0
17 0010 FD7BC1A8 ldp x29, x30, [sp], #16
18 0014 C0035FD6 ret
DEFINED SYMBOLS
HelloWorld.S:2 .data:0000000000000000 mesg
HelloWorld.S:9 .text:0000000000000000 main
HelloWorld.S:9 .text:0000000000000000 $x
UNDEFINED SYMBOLS
printf
program is to be executed next. Chapter 3 and Chapter 4 explain most of the assembly instruc-
tions that are available in AArch64.
2.2 What the assembler does
Listing 2.3 shows how the GNU assembler will assemble the “Hello World” program from
Listing 2.2. The assembler converts the string on input line 2 into the binary representation
of the string. The results are shown in hexadecimal in the Code/Data column of the listing.
The first byte of the string is stored at address 0000,inthe .data section of the program,
as showninthe Addr column on line 2. This line also has a label, which shows up in the
DEFINED SYMBOLS table at the end of the listing.
On line 4, the assembler switches to the .text section of the program and begins converting
instructions into binary. The first instruction, on line 9, is converted into its 4-byte machine
code, FD7BBFA9 16 , and stored at location 0000 in the .text section of the program, as shown
in the Code/Data and Addr columns on line 9. This line also has a label, which shows up in
the DEFINED SYMBOLS table at the end of the listing.