Skip to content

Intel syntax

LIU Hao edited this page May 17, 2023 · 39 revisions

The AT&T syntax for x86 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 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.

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

~/.gdbibit

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

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"]))

Makefile.am

AM_CPPFLAGS = @host_asm_opt@