This set of exercises uses the GNU Assembler (GAS) syntax, which is the syntax that is required by Arm Compiler 6. A full description of the GAS syntax is beyond the scope of these exercises. This section briefly introduces the important pieces of syntax that are needed to complete the exercises.
Here is an example of a short assembler file containing a single function:
.section GCD,"ax" .align 3 .global gcd // uint32_t gcd(uint32_t a, uint32_t b) .type gcd, @function gcd: // // // ADD YOUR CODE HERE // // RET
Going through the code line by line:
.section GCD, “ax”
- This directive defines an ELF section, giving it the name
GCDand marking it as executable (
“ax”). An ELF section is the smallest block of code and data that a compiler or linker can work on.
- The align directive sets the starting alignment of the code, in this case to 2^3 bytes.
- The global directive can be used to either:
- Export a symbol that is defined within this file, making the symbol globally visible
- Import a symbol that will be defined somewhere else
.type gcd, @function
- The type directive tells the tools what a symbol refers to. In this example we are saying that the symbol
gcdrefers to a function.
- This line defines a label called
gcd. A colon (:) is needed after the name. This is different to the assembler syntax that used in the older Arm Compiler tools, for example, Arm Compiler 2.x, Arm Compiler 3.x, Arm Compiler 4.x, and Arm Compiler 5.x.
Looking at the makefile that is used in the template functions, the command to assemble or compile the source files is:
- For C files:
armclang -gdwarf-3 -c -O1 –target=aarch64-arm-none-eabi <file>
- For assembler files:
armclang -gdwarf-3 -c –target=aarch64-arm-none-eabi <file>
Taking the compiler arguments one at a time:
Tells the tool to generate debug data using the Dwarf-3 format. This is necessary to do source-level stepping in the debugger.
This tells the tool only to compile, or assemble, the file and not link. Linking is done as a separate step.
For compiling C files, the level of optimization that is required. Level 1 is one of the lowest, meaning least optimized, which is useful for debugging these simple exercises.
This tells the tools the target architecture ABI, in this case Arm AArch64.
We could also have added:
This would let us specify which version of the architecture to target, for example -march=armv8.1-a means that that Armv8.1-A extensions are supported. The default is Armv8.0-A.