Page 65 - ARM 64 Bit Assembly Language
P. 65

GNU assembly syntax 49

                     With that definition, ‘enum 0,5’ is equivalent to this assembly input:

                    1         .long  0
                    2         .long  1
                    3         .long  2
                    4         .long  3
                    5         .long  4
                    6         .long  5



                     2.4 Chapter summary

                     There are four elements to assembly syntax: labels, directives, instructions, and comments.
                     Directives are used mainly to define symbols, allocate storage, and control the behavior of
                     the assembler. The most common assembler directives were introduced in this chapter, but
                     there are many other directives available in the GNU Assembler. Complete documentation is
                     available on-line as part of the GNU Binutils package.

                     Directives are used to declare statically allocated storage, which is equivalent to declaring
                     global static variables in C. In assembly, labels and other symbols are visible only within
                     the file that they are declared, unless they are explicitly made visible to other files with the
                     .global directive. In C, variables which are declared outside of any function are visible to
                     all files in the program, unless the static keyword is used to make them visible only within
                     the file where they are declared. Thus, both C and assembly support file and global scope for
                     static variables, but with the opposite defaults.
                     Directives can also be used to declare macros. Macros are expanded by the assembler and
                     may generate multiple statements. Careful use of macros can automate some simple tasks,
                     allowing several lines of assembly code to be replaced with a single macro invocation.


                     Exercises

                      2.1. What is the difference between
                            a. the .data section and the .bss section?
                            b. the .ascii and the .asciz directives?
                            c. the .word and the .long directives?
                      2.2. What is the purpose of the .align assembler directive? What does “.align 2”doin
                           GNU AArch64 assembly?
                      2.3. Assembly language has four main elements. What are they?
                      2.4. Using the directives presented in this chapter, show three different ways to create a
                           null-terminated string containing the phrase “segmentation fault”.
   60   61   62   63   64   65   66   67   68   69   70