Using the C preprocessor
armasm can invoke armclang to preprocess an assembly language source file before assembling it. Preprocessing with armclang allows you to use C preprocessor commands in assembly source code.
If you require armclang preprocessing, you must use the
--cpreproc command-line option together with the
--cpreproc_opts command-line option when invoking the assembler. Including these options causes armasm to call armclang to preprocess the file before assembling it.
NoteAs a minimum, you must specify the armclang
--targetoption and either the
To assemble code containing C directives that require the C preprocessor, the input assembly source filename must have an upper-case extension
.S. If your source filenames have a lower-case extension
.s, then to avoid having to rename the files:
- Perform the pre-processing step manually using the
armclang -x assembler-with-cppoption.
- Assemble the preprocessed file without using the
armasm looks for the armclang binary in the same directory as the armasm binary. If it does not find the binary, armasm expects the armclang binary to be on the PATH.
If present on the command line, armasm passes the following options by default to armclang:
- Basic pre-processor configuration options, such as
- User-specified include directories,
- Anything that is specified in
Some of the options that armasm passes to armclang are converted to the armclang equivalent beforehand. These options are shown in the following table:
Table 4-4 armclang equivalent command-line options
armasm correctly interprets the
#line commands. It can generate error
debug_line tables using the information in
Preprocessing an assembly language source file
The following example shows the command that you write to preprocess and assemble a file, source.S. The example also passes the compiler options to define a macro that is called
RELEASE, and to undefine a macro that is called
armasm --cpu=cortex-m3 --cpreproc --cpreproc_opts=--target=arm-arm-none-eabi,-mcpu=cortex-a9,-D,RELEASE,-U,ALPHA source.S
Preprocessing an assembly language source file manually
Alternatively, you must manually call armclang to preprocess the file before calling armasm. The following example shows the commands that you write to manually preprocess and assemble a file, source.S:
armclang --target=arm-arm-none-eabi -mcpu=cortex-m3 -E source.S > preprocessed.S armasm --cpu=cortex-m3 preprocessed.S
In this example, the preprocessor outputs a file that is called preprocessed.S, and armasm assembles it.