assemblygccdisassemblyintel-syntax

gcc gives weird Intel syntax


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?


Solution

  • 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.