Page 54 - ARM 64 Bit Assembly Language
P. 54
38 Chapter 2
data in. Sections can also be further divided into numbered subsections. Each section has its
own address counter, which is used to keep track of the location of bytes within that section.
When a label is encountered, it is assigned the value of the current address counter for the cur-
rently active section.
Selecting a section and subsection is done by using the appropriate assembly directive. Once
a section has been selected, all of the instructions and/or data will go into that section until
another section is selected. The most important directives for selecting a section are:
.data subsection
Instructs the assembler to append the following instructions or data to the data subsec-
tion numbered subsection. If the subsection number is omitted, it defaults to zero.
This section is normally used for global variables and constants, which have labels.
.text subsection
Tells the assembler to append the following statements to the end of the text subsection
numbered subsection. If the subsection number is omitted, subsection number zero is
used. This section is normally used for executable instructions.
.bss subsection
The bss (short for Block Started by Symbol) section is used for defining data storage ar-
eas that should be initialized to zero at the beginning of program execution. The .bss
directive tells the assembler to append the following statements to the end of the bss
subsection numbered subsection. If the subsection number is omitted, subsection
number zero is used. This section is normally used for global variables which need to
be initialized to zero. Regardless of what is placed into the section at compile-time, all
bytes will be set to zero when the program begins executing. This section does not actu-
ally consume any space in the object or executable file. It is really just a request for the
loader to reserve some space when the program is loaded into memory.
.section name
In addition to the three common sections, the programmer can create other sections us-
ing this directive. However in order for custom sections to be linked into a program,
the linker must be made aware of them. With the GNU tools, this can be accomplished
by providing a linker script. That topic is outside the scope of this book, but interested
readers are referred to the GNU linker documentation.
2.3.2 Allocating space for variables and constants
There are several directives that allow the programmer to allocate and initialize static storage
space for variables and constants. The assembler supports bytes, integer types, floating point
types, and strings. These directives are used to allocate a fixed amount of space in memory