To define e.g. 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. In ADS 1.2 and later, you can now include C style #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 - when given a .s file, the compilers ignored -E, but invoked armasm directly instead
- the assemblers did not understand #line.
Solutions for ADS 1.1 (and earlier) Two solutions for ADS 1.1 and earlier are given below: 1) 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 (currently 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.h 2) In your AFS 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.
|