Page 56 - ARM 64 Bit Assembly Language
P. 56
40 Chapter 2
.data
static int i = 0;
i: .word 0
static int j = 1;
j: .word 1
static char fmt[] = "Hello\n";
fmt: .asciz "Hello\n"
static char ch[] = {’A’,’B’,0};
ch: .byte ’A’,’B’,0
static int ary[] = {0,1,2,3,4};
ary: .word 0,1,2,3,4
(B) Declarations in C
(A) Declarations in Assembly
Figure 2.1: Equivalent static variable declarations in Assembly and C.
.float flonums
.single flonums
This directive assembles zero or more floating point numbers, separated by commas.
In AArch64, they are 4-byte IEEE standard single precision numbers. .float and
.single are synonyms.
.double flonums
The .double directive expects zero or more floating point numbers, separated by com-
mas. In AArch64, they are stored as 8-byte IEEE standard double precision numbers.
Fig. 2.1A shows how these directives are used to declare variables and constants. Fig. 2.1B
shows the equivalent statements for creating global variables in C or C++. Note that in both
cases, the variables created will be visible anywhere within the file that they are declared, but
not visible in other files which are linked into the program.
In C, the declaration of an array can be performed by leaving out the number of elements and
specifying an initializer, as shown in the last three lines of Fig. 2.1B. In assembly, the equiv-
alent is accomplished by providing a label, a type, and a list of values, as shown in the last
three lines of Fig. 2.1A. The syntax is different, but the result is precisely the same.
Listing 2.4 shows how the assembler assigns addresses to these labels. The second column
of the listing shows the address (in hexadecimal) that is assigned to each label. The variable
i is assigned the first address. Since it is a word variable, the address counter is incremented
by four bytes and the next address is assigned to the variable j. The address counter is incre-
mented again, and fmt is assigned the address 0008.The fmt variable consumes seven bytes,
so the ch variable gets address 000f. Finally, the array of words named ary begins at address
0012. Note that 12 16 = 18 10 is not evenly divisible by four, which means that the word vari-
ables in ary are not aligned on word boundaries.