3.8. Using the C preprocessor

You can use C preprocessor commands in your assembly language source file. 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 Table 3.16. Some of these options are converted to the armcc equivalent before passing to armcc. These are shown in Table 3.17.

Table 3.16. Command-line options

--16

--arm_only

--diag_error

--diag_warning

--li

--32

--bi

--diag_remark

--fpu

--library_type

--apcs

--cpu

--diag_style

--fpumode

--thumb

--arm

--device

--diag_suppress

--i

--unaligned_access --no_unaligned_access


Table 3.17. armcc equivalent command-line options

armasmarmcc

--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. See the Compiler User Guide for more information. armasm correctly interprets the preprocessed #line commands. It can generate error messages and debug_line tables using the information in the #line commands.

Example 3.1 shows the commands 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.

Example 3.1. Preprocessing an assembly language source file

armasm --cpreproc --cpreproc_opts=-D,RELEASE,-U,ALPHA source.s

If you want to use complex preprocessor options, you must manually call armcc to preprocess the file before calling armasm. Example 3.2 shows the commands you write to manually preprocess and assemble a file, source.s. In this example, the preprocessor outputs a file called preprocessed.s, and armasm assembles preprocessed.s.

Example 3.2. Preprocessing an assembly language source file manually

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

Copyright © 2002-2010 ARM. All rights reserved.ARM DUI 0204J
Non-ConfidentialID101213