| ARM Technical Support Knowledge Articles | |
Applies to: ARM Developer Suite (ADS), RealView Developer Kit (RVDK) for OKI, RealView Developer Kit (RVDK) for ST, RealView Developer Kit for XScale (RVXDK), RealView Development Suite (RVDS), Software Development Toolkit (SDT)
To define, for example, constants in code, it is normal to use #define for C code and EQU for assembler code. You may have a project containing a mix of C and assembler code, where there are some constant definitions which are common to both the C and assembler code. In this case, it is useful to be able to create a list of common definitions that can be included into both C files and assembler files, to avoid maintaining two parallel lists.
#include and #define directives directly in your assembler source. The assembler source can then be passed through the C compiler preprocessor, which outputs a "preprocessed" version of your assembler code, which can then be assembled in the normal way. Consider the following example:----- ex.s -----
#include "my_header.h"
AREA Example, CODE, READONLY
start
MOV r0, #ONE_CONSTANT
ADD r0, r0, r1
MOV pc,lr
END
--- end ex.s ---
where my_header.h contains
#define ONE_CONSTANT 1
When ex.s is passed through the C preprocessor using the following command.
armcc -E ex.s > p_ex.s
The output file p_ex.s looks like this:
---- p_ex.s ----
#line 1 "ex.s"
#line 1 "my_header.h"
#line 2 "ex.s"
AREA Example, CODE, READONLY
start
MOV r0, # 1
ADD r0, r0, r1
MOV pc,lr
END
-- end p_ex.s --
p_ex.s can then be assembled in the normal way with armasm.
Unfortunately, the above cannot be done with ADS 1.1 or earlier because
.s file, the compilers ignored -E, but invoked armasm directly instead#line.In RVDS 4.0, you no longer need to invoke armcc to use C preprocessor macros in an assembly language source file or C preprocessor command-line options. To achieve this you can use the --cpreproc command-line option when invoking the assembler. The --cpreproc_opts command-line option can be used to pass additional options to the compiler. For example: armasm --cpreproc source.s. For more information on these options, please see the RVCT 4.0 Assembler Guide.
Two solutions for ADS 1.1 and earlier are given below:
The file include.zip contains two header files (stdcmac.h and stdsmac.h) which define various C and assembler macros.
If these are included in a project, a restricted C header (only containing #defines) can be included in assembler code. This solution could be extended to support other C directives such as #if, #ifdef, etc. An example header file options.h is also provided.
To include the file options.h in a C file use:
#include "stdcmac.h"
#include "options.h"
To include the file options.h in an assembler file use:
INCLUDE stdsmac.h
INCLUDE options.hIn your ADS or SDT installation you will find the file makelo.c in the Angel / Source directories. This code includes various C headers and then produces text output containing appropriate assembler definitions to match the C defines. Although this code is application specific (i.e. not intended for general use), you may find it helpful as a rough outline if you wish to implement your solution this way.
Attachments: include.zip
Article last edited on: 2009-07-08 11:47:41
Did you find this article helpful? Yes No
How can we improve this article?