Skip to content

Intel syntax

LIU Hao edited this page Sep 27, 2024 · 32 revisions

The AT&T syntax is a horrible mistake. The decision to put up with that piece of evilness is even more horrible.

  1. xmm0 = xmm1 * xmm2 + xmm3
    • should read vfmaddpd xmm0, xmm1, xmm2, xmm3,
    • instead of vfmaddpd %xmm3, %xmm2, %xmm1, %xmm0.
  2. IF eax IS GREATER THAN ecx THEN GO TO label
    • should read cmp eax, ecx; jg label,
    • instead of cmpl %ecx, %eax; jg label which Plan 9 dogs seem to have been aware of, but they refuse to correct all the others.
  3. st(3) -= st
  4. eax = ecx + edx * 2 + 42
    • should read lea eax, dword ptr [rcx + rdx * 2 + 42],
    • instead of leal 42(%rcx,%rdx,2), %eax.

The wrong order of operands is inexcusable and shameful, seen on x86 and m68k but nowhere else. Even some more awful assembly languages prefer the natural destination-source order, such as PowerPC.

If the AT&T syntax was better, why do addps etc. have no operand size suffixes like movl etc. do? And why is movl 0x1234,%eax not movl (0x1234),%eax? And why is jmpq *%rax not jmpq (%rax)? And why is there not an AT&T clone for AVR, ARM, MIPS, RISC-V, etc.?

Those are just random choices that happen to be there, work by accident, and probably nobody wants to fix either because people are used to it or they are incompetent or they just don't care, whatever. It was Plan 9 dogs who couldn't stop making mistakes and earned consequent infamy for themselves.

And Why no one should use the AT&T syntax ever, for any reason, under any circumstances:

Everybody uses Intel! And I mean, everybody. Every assembler, every disassembler, every reverse-engineering tool, every debugger. Documentation from Intel and AMD’s official manuals, as well as most of the unofficial ones. Inline assemblers for the D, Rust, and Zig reference compilers, and Microsoft’s C compiler.

Everybody except for GCC and the GNU toolchain (and its clones, Clang and TCC), who just have to be different.8 All the cool kids are doing it, why won’t you? Even assemblers for other architectures use syntax that looks a lot like Intel syntax. Even the Plan 9 assembler, made by many of the same AT&T employees who made Unix and the original AT&T assembler, walks back on some of AT&T’s horrible mistakes (though unfortunately none of the important ones).9

GCC and Clang

~/.bashrc

alias gcc='gcc -masm=intel'
alias g++='g++ -masm=intel'
alias clang='clang -masm=intel'
alias clang++='clang++ -masm=intel'

GDB

~/.gdbinit

set disassembly-flavor intel
tui new-layout hsplit {-horizontal src 1 asm 1 } 2 cmd 1
layout hsplit
focus cmd

objdump & kcachegrind

~/.bashrc

alias objdump='objdump -Mintel'
OBJDUMP='objdump -Mintel'

(and globally; you need root) /etc/environment

OBJDUMP='objdump -Mintel'

autotools

configure.ac

AC_CHECK_DECL([__i386__], AS_VAR_SET([host_asm_opt], ["-masm=intel -msse2 -mfpmath=sse"]))
AC_CHECK_DECL([__amd64__], AS_VAR_SET([host_asm_opt], ["-masm=intel"]))
## ...
AC_SUBST([host_asm_opt])

Makefile.am

AM_CPPFLAGS = @host_asm_opt@

meson

if meson.get_compiler('c').has_argument('-masm=intel')
  add_project_arguments('-masm=intel', language: [ 'c', 'cpp' ])
endif