如何给 GNU ARM 汇编程序中的寄存器一个不同的名称?
How to give a different name to a register in GNU ARM assembler?
我有 tiva c TM4C123GH6PM 并且我刚刚安装了 GNU ARM 工具链。我只想在汇编中编程,因为我想为它构建一个 FORTH 系统,但是当我使用
.equ W, r2 // working register
这给出了符号 r2
add W, IP, #4
main.S(54): error: undefined symbol r2 used as an immediate value
然后我改成了:
#define W r2
现在给出
add W, IP, #4
main.S(55): error: undefined symbol W used as an immediate value
问题:
- 可以改名吗?
- 如果没有,我可以使用 C 前身吗?
您不能重命名寄存器。
要使用预处理器,您需要使用 GCC 而不是 as
进行编译。除了直接使用arm-none-eabi-cpp
,还有两种方法:
- 使用
.S
(大写)扩展名命名您的程序集文件并使用 GCC 编译(例如 arm-none-eabi-gcc -c foo.S -o foo.o
)。 小写 .s
扩展将跳过预处理。
- 根据需要命名您的程序集文件并将
-x assembler-with-cpp
传递给 GCC(例如 arm-none-eabi-gcc -c -x assembler-with-cpp foo.bar -o foo.o
。使用 -x assembler
而不是跳过预处理。
如果您使用 Keil 进行编译,请使用 .sx
扩展(列出 here)。我找不到像 GCC -x
.
这样的开关
要为寄存器创建别名,请使用 .req
:
W .req r2
...
add W, IP, #4
我有 tiva c TM4C123GH6PM 并且我刚刚安装了 GNU ARM 工具链。我只想在汇编中编程,因为我想为它构建一个 FORTH 系统,但是当我使用
.equ W, r2 // working register
这给出了符号 r2
add W, IP, #4
main.S(54): error: undefined symbol r2 used as an immediate value
然后我改成了:
#define W r2
现在给出
add W, IP, #4
main.S(55): error: undefined symbol W used as an immediate value
问题:
- 可以改名吗?
- 如果没有,我可以使用 C 前身吗?
您不能重命名寄存器。
要使用预处理器,您需要使用 GCC 而不是 as
进行编译。除了直接使用arm-none-eabi-cpp
,还有两种方法:
- 使用
.S
(大写)扩展名命名您的程序集文件并使用 GCC 编译(例如arm-none-eabi-gcc -c foo.S -o foo.o
)。 小写.s
扩展将跳过预处理。 - 根据需要命名您的程序集文件并将
-x assembler-with-cpp
传递给 GCC(例如arm-none-eabi-gcc -c -x assembler-with-cpp foo.bar -o foo.o
。使用-x assembler
而不是跳过预处理。
如果您使用 Keil 进行编译,请使用 .sx
扩展(列出 here)。我找不到像 GCC -x
.
要为寄存器创建别名,请使用 .req
:
W .req r2
...
add W, IP, #4