我想要编写统一的程序集来摆脱在我的文字前面讨厌的#,就像在:Is the hash required for immediate values in ARM assembly?中提到的那样
这是使用#编写的最小非统一代码
#include <assert.h>
#include <inttypes.h>
int main(void) {
uint32_t io = 0;
__asm__ (
"add %0, %0, #1;"
: "+r" (io)
:
:
);
assert(io == 1);
}它可以在QEMU下编译并随后正常运行:
arm-linux-gnueabihf-gcc -c -ggdb3 -march=armv7-a -pedantic -std=c99 -Wall -Wextra \
-fno-pie -no-pie -marm -o 'tmp.o' 'tmp.c'如果我尝试删除#,则代码失败,并显示以下信息:
/tmp/user/20321/ccoBzpSK.s: Assembler messages:
/tmp/user/20321/ccoBzpSK.s:51: Error: shift expression expected -- `add r3,r3,1'不出所料,因为非统一似乎是默认的。
如何做到这一点呢?
我找到了一个很有前途的选择:
gcc -masm-syntax-unified但添加它也无济于事。
如果我改为这样写:
".syntax unified; add %0, %0, #1;"然后它就可以工作了,但我必须为每个__asm__都这样做,这是不实际的。
UI还发现,如果没有-marm,它就会使用统一的程序集,但它会生成缩略代码,这是我不想要的。
也许这个bug是问题的根源:https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88648
测试环境为arm-linux-gnueabi-gcc 5.4.0,Ubuntu 18.04。
发布于 2019-01-10 23:38:17
开发人员很快再次回复了这个问题:https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88648#c3,一个补丁被提交到:https://github.com/gcc-mirror/gcc/commit/2fd2b9b8425f9fc4ad98d48a0ca41b921dd75bd9 (post 8.2.0)修复-masm-syntax-unified。太棒了!
https://stackoverflow.com/questions/54078112
复制相似问题