You copied the Doc URL to your clipboard.

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 --cpreproc 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.

Note

As a minimum, you must specify the armclang --target option and either the -mcpu or -march option with --cpreproc_opts.

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 -E.
  • User specified include directories, -I directives.
  • User specified licensing options, such as --site_license.
  • Anything specified in --cpreproc_opts.

Some of the options that armasm passes to armclang are converted to the armclang equivalent beforehand. These are shown in the following table:

Table 8-4 armclang equivalent command-line options

armasm armclang
--thumb -mthumb
--arm -marm
-i -I

armasm correctly interprets the preprocessed #line commands. It can generate error messages and debug_line tables using the information in the #line commands.

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 ALPHA.

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.

Was this page helpful? Yes No