Page 53 - ARM 64 Bit Assembly Language
P. 53

GNU assembly syntax 37

                     Next, the assembler converts the adr instruction on line 12 into the four-byte machine instruc-
                     tion 00000010 16 andstoresitataddress 0004. It repeats this process with each remaining
                     instruction until the end of the program. The assembler writes the resulting data into a spe-
                     cially formatted file, called an object file. Note that the assembler was unable to locate the
                     printf function. The linker will take care of that. The object file created by the assembler,
                     hello.o, contains the data in the Code column of Listing 2.3, along with information to help
                     the linker to link (or “patch”) the instruction on line 13 so that printf is called correctly.

                     After creating the object file, the next step in creating an executable program would be to in-
                     voke the linker and request that it link hello.o with the C standard library. The linker will
                     generate the final executable file, containing the code assembled from hello.s, along with
                     the printf function and other start-up code from the C standard library. The GNU C com-
                     piler is capable of automatically invoking the assembler for files that end in .s or .S, and can
                     also be used to invoke the linker. For example, if Listing 2.2 is stored in a file named hello.S
                     in the current directory, then the command
                        gcc -o hello hello.S

                     will run the GNU C compiler, telling it to create an executable program file named hello,
                     andtouse hello.S as the source file for the program. The C compiler will notice the .S ex-
                     tension, and invoke the assembler to create an object file which is stored in a temporary file,
                     possibly named hello.o. Then the C compiler will invoke the linker to link hello.o with
                     the C standard library, which provides the printf function and some start-up code which
                     calls the main function. The linker will create an executable file named hello. When the
                     linker has finished, the C compiler will remove the temporary object file.



                     2.3 GNU assembly directives

                     Each processor architecture has its own assembly language, created by the designers of the
                     architecture. Although there are many similarities between assembly languages, the designers
                     may choose different names for various directives. The GNU assembler supports a relatively
                     large set of directives, and some of them have more than one name. This is because it is de-
                     signed to handle assembling code for many different processors, without drastically changing
                     the assembly language designed by the processor manufacturers. We will now cover some of
                     the most commonly used directives for the GNU assembler.



                     2.3.1 Selecting the current section
                     The instructions and data that make up a program are stored in different sections of the pro-
                     gram file. There are several standard sections that the programmer can choose to put code and
   48   49   50   51   52   53   54   55   56   57   58