gcc 给出了奇怪的 Intel 语法
我一直试图通过使用编译器生成不同优化级别的各种 C 程序的汇编程序来更好地了解幕后发生的情况。有件事困扰我一段时间了。
当我按如下方式编译 tc 时,
gcc -S t.c
我得到 AT&T 语法的程序集,如下所示。
function:
pushl %ebp
movl %esp, %ebp
movl 12(%ebp), %eax
addl 8(%ebp), %eax
popl %ebp
ret
.size function, .-function
当我使用 masm 参数进行编译时,如下所示:-
gcc -S t.c -masm=intel
我得到以下输出。
function:
push %ebp
mov %ebp, %esp
mov %eax, DWORD PTR [%ebp+12]
add %eax, DWORD PTR [%ebp+8]
pop %ebp
ret
.size function, .-function
语法发生了变化,但寄存器符号之前仍然有“%”(这就是为什么我一开始就不喜欢 AT&T 语法)。
有人可以解释为什么会发生这种情况吗?我该如何解决这个问题?
I have been trying to get a better idea of what happens under the hood by using the compiler to generate the assembly programs of various C programs at different optimization levels. There is something that has been bothering me for a while.
When I compile t.c
as follows,
gcc -S t.c
I get the assembly in AT&T syntax as follows.
function:
pushl %ebp
movl %esp, %ebp
movl 12(%ebp), %eax
addl 8(%ebp), %eax
popl %ebp
ret
.size function, .-function
When I compile using the masm argument as follows:-
gcc -S t.c -masm=intel
I get the following output.
function:
push %ebp
mov %ebp, %esp
mov %eax, DWORD PTR [%ebp+12]
add %eax, DWORD PTR [%ebp+8]
pop %ebp
ret
.size function, .-function
There is a change in syntax but there are still "%"s before the notation of registers(this is why I don't prefer AT&T syntax in the first place).
Can someone shed some light on why this is happening? How do I solve this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
GNU 汇编器(gas)确实有一个单独的选项来控制 % 前缀。文档似乎表明 GCC 没有这样的选项,但我的 GCC(版本 Debian 4.3.2-1.1)不会生成 % 前缀。
The GNU assembler (gas) does have a separate option for controlling the % prefix. Documentation seems to suggest GCC doesn't have such an option, but my GCC (version Debian 4.3.2-1.1) doesn't produce the % prefix.
我认为您在反汇编时除了获得英特尔语法之外,我不确定,但请尝试以下步骤,
参考我分享的这张图片
I think you excepted to get intel syntex while disassemble, I'm not sure but try this following steps,
Refer this image, which i shared