Page 50 - ARM 64 Bit Assembly Language
P. 50
34 Chapter 2
Listing 2.1 “Hello World” program in C.
1 #include <stdio.h>
2 /*
3 * Prints "Hello World\n" and returns 0.
4 */
5 int main(void) {
6 printf("Hello World\n");
7 return 0;
8 }
Listing 2.1 shows an equivalent program written in C. The assembly language version of the
program is significantly more lines than the C version, and will only work on an AArch64
processor or emulator. The C version is at a higher level of abstraction, and can be compiled
to run on any system that has a C compiler. Thus, C is referred to as a high-level language,
and assembly as a low-level language.
2.1.1 Labels
Most modern assemblers are called two-pass assemblers because they read the input file
twice. On the first pass, the assembler keeps track of the location of each piece of data and
each instruction, and assigns an address or numerical value to each label and symbol in the
input file. The main goal of the first pass is to build a symbol table, which maps each label or
symbol to a numerical value.
On the second pass, the assembler converts the assembly instructions and data declarations
into binary, using the symbol table to supply numerical values whenever they are needed. In
Listing 2.2, there are two labels: main and message. During assembly, those labels are as-
signed the value of the address counter at the point where they appear. Labels can be used
anywhere in the program to refer to the address of data, functions, or blocks of code. In GNU
assembly syntax, label definitions always end with a colon (:) character.
2.1.2 Comments
In the GNU assembler, there are two basic comment styles: multi-line and single-line. Multi-
line comments start with /* and everything is ignored until a matching sequence of */ is
found. These comments are exactly the same as multi-line comments in C and C++. Single
line comments begin with //, and all remaining characters on the line are ignored. This is the
same as single line comments in C++. Listing 2.2 shows both types of comment.