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

Note

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

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:

  1. Perform the pre-processing step manually using the armclang -x assembler-with-cpp option.
  2. Assemble the preprocessed file without using the --cpreproc and --cpreproc_opts options.

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 -E.
  • User-specified include directories, -I directives.
  • Anything that is specified in --cpreproc_opts.

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

Was this page helpful? Yes No