Page 59 - ARM 64 Bit Assembly Language
P. 59

GNU assembly syntax 43


                                         Listing 2.5 A listing with properly aligned data.

                      ARM GAS  variable2.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




                     and directives are one type of symbol. The programmer can also declare other symbols and
                     use them throughout the program. Such symbols may not have an actual storage location in
                     memory, but they are included in the assembler’s symbol table, and can be used anywhere
                     that their value is required. The most common use for defined symbols is to allow numeri-
                     cal constants to be declared in one place and easily changed. The .equ directive allows the
                     programmer to use a label instead of a number throughout the program. This contributes to
                     readability, and has the benefit that the constant value can then be easily changed every place
                     that it is used, just by changing the definition of the symbol. The most important directives
                     related to symbols are:

                       .equ symbol, expression
                       .set symbol, expression
                          This directive sets the value of symbol to expression. It is similar to the C language
                          #define directive.
                       .equiv symbol, expression
                          The .equiv directive is like .equ and .set, except that the assembler will signal an
                          error if the symbol is already defined.
                       .global symbol
                       .globl symbol
                          This directive makes the symbol visible to the linker. If symbol is defined within a file,
                          and this directive is used to make it global, then it will be available to any file that is
   54   55   56   57   58   59   60   61   62   63   64