1

When I compile the following code to asm in GCC on cygwin:

int scheme_entry() {
  return 42;
}

using:

gcc -O3 --omit-frame-pointer -S test1.c

I get the following 'ASM' generated:

    .file   "test1.c"
    .text
    .p2align 4,,15
.globl _scheme_entry
    .def    _scheme_entry;  .scl    2;  .type   32; .endef
_scheme_entry:
    movl    $42, %eax
    ret

But the 'MOVL' command isn't actually x86 ASM. From looking at the following lists:

http://ref.x86asm.net/geek.html#x0FA0

http://en.wikipedia.org/wiki/X86_instruction_listings

There is no MOVL command, but there is

CMOVL
CMOVLE
MOVLPS
MOVLPD
MOVLHPS

My question is - is gcc ASM "simplified ASM"? If so - how do I map it to 'real ASM'?

hawkeye
  • 34,745
  • 30
  • 150
  • 304
  • 4
    AT&T syntax should be shot in the head. I don't know why anyone uses it – James Apr 22 '12 at 01:56
  • @James I prefer AT&T syntax because I find it cleaner and easier to read. It also flows better since the source operand comes first. – ughoavgfhw Apr 22 '12 at 02:22

2 Answers2

3

GCC uses AT&T syntax. One of the differences is that operand sizes can be specified using an instruction suffix, and the compiler will always use these suffixes. This is actually a mov instruction with an l suffix, which means a 32-bit operand size.

ughoavgfhw
  • 39,734
  • 6
  • 101
  • 123
  • Ah! So you're hinting that I should be doing this: http://stackoverflow.com/questions/199966/how-do-you-use-gcc-to-generate-assembly-code-in-intel-syntax – hawkeye Apr 22 '12 at 01:48
3

As mentioned by ughoavgfhw, GCC outputs AT&T syntax by default, which is different to the Intel-style syntax you seem to be expecting. This behaviour, however, is configurable: you can request it to output Intel-style as follows:

gcc -masm=intel -O3 --omit-frame-pointer -S test1.c

with the key parameter being -masm=intel.

Using this command line, the assembly output I get (with a few unnecessary lines cut out for brevity) is as follows:

scheme_entry:
    mov eax, 42
    ret
davidg
  • 5,868
  • 2
  • 33
  • 51