Using the C preprocessor
armasm can invoke armclang to preprocess an assembly language source file before assembling it. This allows you to use C preprocessor commands in assembly source code.
If you do this, you must use the
command-line option together with the
--cpreproc_opts command-line option when invoking the assembler. This causes
armasm to call armclang to preprocess the file before assembling it.
NoteAs a minimum, you must specify the armclang
--targetoption and either the
armasm looks for the armclang binary in the same directory as the armasm binary. If it does not find the binary, it expects it to be on the PATH.
armasm passes the following options by default to armclang if present on the command line:
- Basic pre-processor configuration options, such as
- User specified include directories,
- User specified licensing options, such as
- Anything specified in
Some of the options that armasm passes to armclang are converted to the armclang equivalent beforehand. These 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 you write to preprocess and
assemble a file, source.S. The example also passes the
compiler options to define a macro called
RELEASE, and to
undefine a macro 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 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 called preprocessed.S, and armasm assembles it.