In case you do not know assembly, let me introduce it briefly: x86 Assembly, which is mnemonic version of underlying x86 machine code, has two main syntax: AT&T syntax (or GAS syntax) and Intel syntax.
AT&T/GAS syntax:
movl $5, %eax
addl 5(%ebp,%ebx,4), %eax
movsbl 6(%ebp,%edx,1), %ecx
addl %ecx, %eax
ret
Intel syntax:
mov eax, 5
add eax, [ebp+ebx*4+5]
movsx ecx, BYTE PTR [ebp+edx+6]
add eax, ecx
ret
While technically, I can read and write in both syntaxes, I vastly prefer the Intel syntax. Distinct differences between the two syntaxes are:
- Argument position. AT&T/GAS and Intel have opposite argument position.
- Memory addressing. AT&T/GAS use
displacement(base, index, scale)
while Intel use[base+index*scale+displacement]
. - Operand size. AT&T/GAS need explicit size on each instruction, while Intel infers size automatically from the register type, and only require size explicitly when using size-changing instruction (e.g. movsx) with memory operand.
- Operand prefix. AT&T/GAS requires $ prefix for immediate operand, and % for register operand. Intel requires none.
I really do think that the Intel memory operand makes more sense, as all instructions are destructive. I think that mov eax, ecx
means eax := ecx
, while with AT&T the movl %ecx, %eax
means eax := ecx
.
Addressing memory in AT&T syntax are less prone to error, but it’s much harder to read. Yes, with Intel syntax it may not be obvious that it can only be in that form, and may think that you can stick heavy maths in it. But the Intel syntax is how the address is actually calculate.
Let’s talk about assemblers (little programs that convert assembly code to machine code). Only GAS (GNU Assembler) supports AT&T syntax, while every assembler (including GAS) supports Intel syntax. Furthermore, x86 is developed by Intel. It would make more sense to use your manufacturer’s syntax.
Yes, AT&T’s syntax is more clear, more concise, and less prone to error. But writing Intel seems more bliss to me.
Right now, most applications in the Linux/OSS world use AT&T/GAS syntax, while Windows uses Intel syntax.
This post may look like a rant because it’s a rant. I really, really hate reading AT&T syntax. It just does not click with me. Please, if you can, do use Intel syntax.