看如下汇编文件:
1 2 3 4 5 | #define NUM 1000 ldr pc, =NUM#if defined(NUM) mov r1, #2#endif |
AS无法处理带C预处理指令的汇编代码,根据as manual:
It does not do macro processing, include file handling, or anything else you may get
from your C compiler’s preprocessor. You can do include file processing with the .include
directive (see Section 7.62 [.include], page 55). You can use the gnu C compiler driver
to get other “CPP” style preprocessing by giving the input file a ‘.S’ suffix.
对于有C预处理指令的汇编代码,需要有GCC处理:
使用CPP预处理
1 2 3 4 5 6 7 8 9 10 11 12 | herbert@herbert-pc:/work/code/arm_as/sym$ $CPP sym.S# 1 "sym.S"# 1 "<built-in>"# 1 "<command-line>"# 31 "<command-line>"# 1 "/work/toolchain/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi/sysroot/usr/include/stdc-predef.h" 1 3 4# 32 "<command-line>" 2# 1 "sym.S"ldr pc, =1000mov r1, #2 |
使用GCC汇编:
1 2 3 4 5 6 7 8 9 10 11 | herbert@herbert-pc:/work/code/arm_as/sym$ $CC -c sym.S herbert@herbert-pc:/work/code/arm_as/sym$ $OBJDUMP -d sym.osym.o: file format elf32-littlearmDisassembly of section .text:00000000 <.text>: 0: e3a0fffa mov pc, #1000 ; 0x3e8 4: e3a01002 mov r1, #2 |