Page 60 - ARM 64 Bit Assembly Language
P. 60
44 Chapter 2
Listing 2.6 Defining a symbol for the number of elements in an array.
ARM GAS variable3.S page 1
line addr value code
1 .data
2 0000 00000000 i: .word 0
3 0004 01000000 j: .word 1
4 0008 48656C6C fmt: .asciz "Hello\n"
4 6F0A00
5 000f 414200 ch: .byte ’A’,’B’,0
6 0012 0000 .align 2
7 0014 00000000 ary: .word 0,1,2,3,4
7 01000000
7 02000000
7 03000000
7 04000000
8 .equ arysize,(. - ary)/4
9
DEFINED SYMBOLS
variable3.S:2 .data:0000000000000000 i
variable3.S:3 .data:0000000000000004 j
variable3.S:4 .data:0000000000000008 fmt
variable3.S:5 .data:000000000000000f ch
variable3.S:6 .data:0000000000000012 $d
variable3.S:7 .data:0000000000000014 ary
variable3.S:8 *ABS*:0000000000000005 arysize
NO UNDEFINED SYMBOLS
linked with the one containing the symbol. Without this directive, symbols are visible
only within the file where they are defined.
.comm symbol, length
This directive declares symbol to be a common symbol, meaning that if it is defined in
more than one file, then all instances should be merged into a single symbol. If the sym-
bol is only defined in one file, then the linker will allocate length bytes of uninitialized
memory. If there are multiple definitions for symbol, and they have different sizes, the
linker will merge them into a single instance using the largest size defined.
Listing 2.6 shows how the .equ directive can be used to create a symbol holding the number
of elements in an array. The symbol arysize is defined as the value of the current address
counter (denoted by the .) minus the value of the ary symbol, divided by four (each word in
the array is four bytes). The listing shows all of the symbols defined in this program segment.