user277465
user277465

Reputation:

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?

Upvotes: 3

Views: 419

Answers (2)

Elamurasu
Elamurasu

Reputation: 3

I think you excepted to get intel syntex while disassemble, I'm not sure but try this following steps,

  1. gcc <filename.c>
  2. gdb ./a.out
  3. set disassembly intel
  4. disassemble main

Refer this image, which i shared

Upvotes: -1

Jester
Jester

Reputation: 58762

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.

Upvotes: 4

Related Questions