代码之家  ›  专栏  ›  技术社区  ›  hyperlogic

如何使用gcc生成intel语法中的汇编代码?

  •  138
  • hyperlogic  · 技术社区  · 16 年前

    这个 gcc -S 选项将以AT&T语法生成程序集代码,是否有方法以Intel语法生成文件?还是有办法在两者之间转换?

    3 回复  |  直到 11 年前
        1
  •  179
  •   Community CDub    7 年前

    你试过这个吗?

    gcc -S -masm=intel test.c
    

    未经测试,但我在这里面找到了 forum 有人声称这对他们有用。

    我刚在Mac上尝试过,但失败了,所以我查看了我的主页:

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

    它可能在你的平台上工作。

    对于Mac OSX:

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

    来源: https://stackoverflow.com/a/11957826/950427

        2
  •  15
  •   phoxis    14 年前

    这个

    gcc -S -masm=intel test.c
    

    和我一起工作。但我可以用另一种方式来解释,尽管这与运行gcc无关。 编译可执行文件或对象代码文件,然后使用objdump以Intel ASM语法反汇编对象代码,如下所示:

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

    这可能会有所帮助。

        3
  •  5
  •   Andro Selva Anand Wadhwani    12 年前

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

    #include <conio.h>
    #include <stdio.h>
    #include <windows.h>
    
    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;
     };
    

    这是使用GCC命令行的代码:

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

    它将生成*.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.
    

    这就是全部。