Sunday, May 29, 2011

Intel vs AT&T syntax

There're two popular assembly syntaxes: Intel and AT&T. Intel syntax is popular in Windows world. In Linux, AT&T syntax is more popular though GAS (Gnu Assembler) supports both.

The following lists some major differences of the two syntaxes:

  1. AT&T prefixes register with % sign
    * Intel:
       eax, ebx, ecx,...
    * AT&T:
       prefix by % sign: %eax, %ebx, %ecx,...

  2. AT&T prefixes immediate value with $ sign, Intel is not
    * Intel: 10, 80h
    * AT&T: $10, $0x80

  3. AT&T and Intel syntax use opposite instruction operands
    * Intel:      mnemonic destination, source 
       Ex:         mov eax, 100
    * AT&T:  mnemonic source, destination
       Ex:        movl $100, %eax

  4. AT&T suffixes instruction to specify instruction's operand size (1 byte: b, 2 bytes: w, 4 bytes: l) but Intel uses directive before operands (1 byte: byte ptr, 2 bytes: word ptr, 4 bytes: dword ptr)
    * Intel:
       mov al, byte ptr foo
    * AT&T:
       movb foo, %al

No comments: