热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何使用gcc以英特尔语法生成汇编代码?-HowdoyouusegcctogenerateassemblycodeinIntelsyntax?

Thegcc-SoptionwillgenerateassemblycodeinAT&Tsyntax,isthereawaytogeneratefilesi

The gcc -S option will generate assembly code in AT&T syntax, is there a way to generate files in Intel syntax? Or is there a way to convert between the two?

gcc -S选项将以AT&T语法生成汇编代码,有没有办法用Intel语法生成文件?或者有没有办法在两者之间进行转换?

3 个解决方案

#1


178  

Have you tried this?

你试过这个吗?

gcc -S -masm=intel test.c

Untested, but I found it in this forum where someone claimed it worked for them.

未经测试,但我发现它在这个论坛中有人声称它为他们工作。

I just tried this on the mac and it failed, so I looked in my man page:

我只是在Mac上尝试了这个并且它失败了,所以我查看了我的手册页:

   -masm=dialect
       Output asm instructions using selected dialect.  Supported choices
       are intel or att (the default one).  Darwin does not support intel.

It may work on your platform.

它可能适用于您的平台。

For Mac OSX:

对于Mac OSX:

clang++ -S -mllvm --x86-asm-syntax=intel test.cpp

Source: https://stackoverflow.com/a/11957826/950427

#2


15  

The

gcc -S -masm=intel test.c

Does work with me. But i can tell another way, although this has nothing to do with running gcc. Compile the executable or the object code file and then disassemble the object code in Intel asm syntax with objdump as below:

和我一起工作吗但我可以告诉另一种方式,虽然这与运行gcc无关。编译可执行文件或目标代码文件,然后用objdump反汇编Intel asm语法中的目标代码,如下所示:

 objdump -d --disassembler-optiOns=intel a.out

This might help.

这可能有所帮助。

#3


5  

I have this code in CPP file:

我在CPP文件中有这个代码:

#include 
#include 
#include 

int a = 0;
int main(int argc, char *argv[]) {
    asm("mov eax, 0xFF");
    asm("mov _a, eax");
    printf("Result of a = %d\n", a);
    getch();
    return 0;
 };

That's code worked with this GCC command line:

该代码适用于此GCC命令行:

gcc.exe File.cpp -masm=intel -mconsole -o File.exe

It will result *.exe file, and it worked in my experience.

它将导致* .exe文件,并且它在我的经验中起作用。

Notes:
immediate operand must be use _variable in global variabel, not local variable.
example: mov _nLength, eax NOT mov $nLength, eax or mov nLength, eax

A number in hexadecimal format must use at&t syntax, cannot use intel syntax.
example: mov eax, 0xFF -> TRUE, mov eax, 0FFh -> FALSE.

That's all.


推荐阅读
author-avatar
手机用户2602897931
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有