6.15 Using the C preprocessor

The assembler can invoke the compiler 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 when invoking the assembler. This causes armasm to call armcc to preprocess the file before assembling it.

armasm looks for the armcc 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 certain options to armcc if present on the command line. These are shown in the following table:

Table 6-5 Command-line options

--16

--bi

--diag_suppress

--li

--32

--cpu

--diag_warning

--library_type

--apcs

--diag_error

--fpu

--thumb

--arm

--diag_remark

--fpumode

--unaligned_access, --no_unaligned_access

--arm_only

--diag_style

-i

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

Table 6-6 armcc equivalent command-line options

armasm armcc

--16

--thumb

--32

--arm

-i

-I

To pass other simple compiler options, such as the preprocessor option -D, you must use the --cpreproc_opts command-line option. 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 --cpreproc --cpreproc_opts=-D,RELEASE,-U,ALPHA source.s

Preprocessing an assembly language source file manually

If you want to use complex preprocessor options, you must manually call armcc to preprocess the file before calling armasm. The following example shows the commands you write to manually preprocess and assemble a file, source.s:

armcc -E source.s > preprocessed.s
armasm preprocessed.s

In this example, the preprocessor outputs a file called preprocessed.s, and armasm assembles it.

Non-ConfidentialPDF file icon PDF versionARM DUI0473M
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.