The following information applies to SDT only. For ADS 1.2, 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, to produce a "preprocessed" version of your assembler code. Description To define e.g. constants in code, it is normal to use #define for C code and EQU for assembler code. However, some definitions may be common to both the C and assembler code, so 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. Solution This solution makes use of the text-processing capabilities of the sed editor as found on UNIX systems (DOS versions of sed are also available). Suppose you have a file 'test.s' which looks like the following:
#include "test.h"
AREA foo, CODE MOV r0, #FOOBAR END
and the file 'test.h' contains the following
#define FOOBAR 1
Then do the following commands:
armcc -E - < test.s | sed /^#/d > /tmp/tmp.s armasm -o test.o /tmp/tmp.s
How this works: - The '-E' option on armcc tells the compiler to apply the preprocesser phase of compilation only and write the output to stdout.
- The '-' means take the input from stdin. You cannot specify the file 'test.s' directly on the armcc command line because armcc will assume it is an assembler file and pass it to armasm for processing.
- This performs all the C preprocessor substitution, however it leaves lines of the form: #line 1 "" in the output file which armasm will not recognize, so pipe it through 'sed /^#/d' to deletes all lines starting with '#'.
- The resulting output is then written to /tmp/tmp.s which can then be assembled back to test.o. Unfortunately armasm will not accept input from stdin otherwise it would be possible to do it all on one line without a temporary file.
|