首页 > 解决方案 > GCC with -masm=intel produces AT&T syntax

问题描述

Below is a gcc command line string I used to output to assembly language listing using -masm=intel. Both command line strings work, but they both produce AT&T syntax, not Intel syntax.

gcc -S -masm=intel Svx.c

but that produces a mixed Intel and AT&T syntax.

      .file "Svx.c"
    .intel_syntax noprefix
    .text
    .globl  main
        .type   main, @function
    main:
.LFB0:
        .cfi_startproc
    push    rbp
    .cfi_def_cfa_offset 16
    .cfi_offset 6, -16
    mov rbp, rsp
    .cfi_def_cfa_register 6
    mov DWORD PTR -4[rbp], 0
    jmp .L2
.L3:
    add DWORD PTR -4[rbp], 1
.L2:
    cmp DWORD PTR -4[rbp], 1000000000
    jne .L3
    mov eax, DWORD PTR -4[rbp]
    pop rbp
    .cfi_def_cfa 7, 8
    ret
    .cfi_endproc
.LFE0:
    .size   main, .-main
    .ident  "GCC: (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0"
    .section    .note.GNU-stack,"",@progbits

The output looks like a modified Intel syntax, but the AT&T-specific cfi directives for stack handling are not translated. And add DWORD PTR -4[rbp],1 is not Intel syntax.

Why do I get mixed AT&T and Intel syntax with -masm=intel?

标签: gcc

解决方案


CFI 指令是GNU 汇编器的指令。通常,此类指令(以 a 开头.)与您选择的汇编语言无关,因此您担心的行不是“AT&T 特定的”,甚至与 AT&T 无关。

并且add DWORD PTR -4[rbp],1 英特尔语法。


推荐阅读