Page 49 - ARM 64 Bit Assembly Language
P. 49

CHAPTER 2

                     GNU assembly syntax




                     All modern computers consist of three main components: the central processing unit (CPU),
                     memory, and devices. It can be argued that the major factor that distinguishes one computer
                     from another is the CPU architecture. The architecture determines the set of instructions that
                     can be performed by the CPU. The human-readable language which is closest to the CPU ar-
                     chitecture is assembly language. When a new processor architecture is developed, its creators
                     also define an assembly language for the new architecture. In most cases, a precise assembly
                     language syntax is defined and an assembler is created by the processor developers. Because
                     of this, there is no single syntax for assembly language, although most assembly languages
                     are similar in many ways, and have certain elements in common. The GNU assembler (GAS)
                     is a highly portable re-configurable assembler. GAS uses a simple and general syntax that
                     works for a wide variety of architectures.



                     2.1 Structure of an assembly program

                     An assembly program consists of four basic elements: assembler directives, labels, as-
                     sembly instructions, and comments. Assembler directives allow the programmer to re-
                     serve memory for the storage of variables, control which program section is being used,
                     define macros, include other files, and perform other operations that control the conver-
                     sion of assembly instructions into machine code. The assembly instructions are given as
                     mnemonics, or short character strings that are easier for human brains to remember than
                     sequences of binary, octal, or hexadecimal digits. Each assembly instruction may have an op-
                     tional label, and most assembly instructions require the programmer to specify one or more
                     operands.
                     Most assembly language programs are written in lines of 80 characters organized into four
                     columns. The first column is for optional labels. The second column is for assembly instruc-
                     tions or assembler directives. The third column is for specifying operands, and the fourth
                     column is for comments. Traditionally, the first two columns are 8 characters wide, the third
                     column is 16 characters wide, and the last column is 48 characters wide. However, most mod-
                     ern assemblers (including GAS) do not require fixed column widths. Listing 2.2 shows a basic
                     “Hello World” program written in AArch64 Assembly to run under Linux. For comparison,


                     ARM 64-Bit Assembly Language
                     https://doi.org/10.1016/B978-0-12-819221-4.00009-2  33
                     Copyright © 2020 Elsevier Inc. All rights reserved.
   44   45   46   47   48   49   50   51   52   53   54