Skip to content
systemcoding.dev
Assembly

Intel vs AT&T Syntax: How to Read Both Without Getting Lost

Read x86 assembly in Intel and AT&T syntax with a six-rule translation method, a side-by-side table of operands and addressing, and a guide to choosing one.

7 min read
Summarize in AI
Flat illustration of an editor window full of code, with the Intel, GNU and C++ logos.

Open a GCC listing and you read movl $5, -4(%rbp). Open the Intel manual and the same instruction is mov dword ptr [rbp - 4], 5. Neither is wrong, the machine code is c7 45 fc 05 00 00 00 either way, and the two notations are about equally old. The trouble is that tutorials, debuggers, kernel sources and manuals disagree about which to use, so an assembly reader has to be fluent in both. This post gives a small set of rules that translate any line from one to the other, a table of the places where the meaning shifts, and a decision table for choosing a syntax for your own work. The examples use x86-64, GNU binutils 2.42 and NASM 2.16. The full tables for every construct are in the cornerstone guide to NASM, GAS and assembler syntax; this post is the short method.

The six rules

Every line translates by applying these in order.

  1. Reverse the operands. Intel is op dest, src; AT&T is op src, dest. For instructions with three operands, such as imul rax, rbx, 10, AT&T reverses the whole list: imulq $10, %rbx, %rax.

  2. Add or drop the register prefix. AT&T writes %rax, Intel writes rax.

  3. Add or drop the immediate prefix. AT&T writes $5, Intel writes 5. In AT&T the same $ also marks a symbol's address: $msg is the address of msg.

  4. Convert the size. AT&T puts a suffix on the mnemonic, movb, movw, movl, movq. Intel puts a keyword before the memory operand when needed, byte ptr, word ptr, dword ptr, qword ptr. When a register operand already fixes the size, both sides may leave it out.

  5. Rewrite the memory operand. Intel is [base + index*scale + disp]; AT&T is disp(base,index,scale).

  6. Mark indirect branches. AT&T writes * before an indirect target: call *%rax. Intel writes call rax with no marker.

Apply them to the opening example in AT&T, movl $5, -4(%rbp). Reverse the operands: -4(%rbp), $5. Drop the prefixes: -4(rbp), 5. The l suffix means 32 bits, so the memory needs dword ptr. Rewrite the memory operand as [rbp - 4]. The result is mov dword ptr [rbp - 4], 5. Going the other way is the same list run backwards.

Side by side

The table below covers what appears in real listings. The Intel column uses the dword ptr spelling that objdump -M intel prints; NASM drops ptr and writes dword [rbp - 4].

MeaningIntelAT&T
Register copymov rax, rbxmovq %rbx, %rax
Immediate loadmov eax, 60movl $60, %eax
Load from memorymov eax, dword ptr [rbx]movl (%rbx), %eax
Store to memorymov dword ptr [rbx], eaxmovl %eax, (%rbx)
Store an immediatemov dword ptr [rbx], 7movl $7, (%rbx)
Displacementmov rax, [rbp - 8]movq -8(%rbp), %rax
Index with scalemov eax, [rdi + rcx*4]movl (%rdi,%rcx,4), %eax
Full formmov eax, [rdi + rcx*4 + 16]movl 16(%rdi,%rcx,4), %eax
Address of a symbolmov edi, offset msgmovl $msg, %edi
RIP-relative addresslea rsi, [rip + msg]leaq msg(%rip), %rsi
Zero-extending loadmovzx eax, byte ptr [rbx]movzbl (%rbx), %eax
Sign-extending loadmovsx rax, dword ptr [rbx]movslq (%rbx), %rax
Indirect callcall raxcall *%rax
Indirect call through memorycall qword ptr [rax + 8]call *8(%rax)
Comparecmp rax, rbxcmpq %rbx, %rax
Segment accessmov rax, qword ptr fs:[0x28]movq %fs:0x28, %rax

Two extension mnemonics are worth memorizing because they look unrelated. movzx and movsx become movz and movs plus two size letters, source then destination: movzbl is "move zero-extended byte to long". And cdqe, cqo and cdq become cltq, cqto and cltd.

The three places where meaning, not just spelling, changes

Most of the translation is mechanical. Three places are not, and they are where people get lost.

The first is the operand order of comparisons. cmp rax, rbx followed by jl jumps when RAX is less than RBX. In AT&T the same test is cmpq %rbx, %rax, and anyone who translates the operands without thinking about the jump inverts the condition. The cure is to read AT&T comparisons from right to left: the right operand is the one being tested.

The second is what a bare symbol means. In NASM, mov rax, msg loads the address of msg, and mov rax, [msg] loads the contents. In AT&T, movq $msg, %rax loads the address and movq msg, %rax loads the contents. In GAS's Intel mode, selected with .intel_syntax noprefix, a bare symbol is a memory reference, so mov rax, msg loads the contents and mov rax, offset msg loads the address. That makes GAS Intel syntax and NASM the same in shape and opposite in this one rule.

The third is operand size inference. AT&T infers the suffix from a register operand, so mov %eax, (%rbx) is accepted as movl. When there is no register, as in $5, (%rbx), there is nothing to infer from and GAS reports ambiguous operand size. Intel needs the keyword in the same cases and NASM reports operation size not specified.

Reading real compiler output

Compile a tiny function and read both outputs. The source:

sum.cc
long sum3(long *p, long i)
{
    return p[i] + p[i + 1] + p[i + 2];
}
Shell
gcc -O2 -S sum.c -o sum-att.s
gcc -O2 -S -masm=intel sum.c -o sum-intel.s

GCC 14 produces, in AT&T syntax and then Intel syntax:

asm
sum3:
    movq    (%rdi,%rsi,8), %rax
    addq    8(%rdi,%rsi,8), %rax
    addq    16(%rdi,%rsi,8), %rax
    ret
asm
sum3:
    mov     rax, QWORD PTR [rdi+rsi*8]
    add     rax, QWORD PTR [rdi+8+rsi*8]
    add     rax, QWORD PTR [rdi+16+rsi*8]
    ret

Read the AT&T version with the rules: each (%rdi,%rsi,8) is [rdi + rsi*8], the leading 8 or 16 is the displacement, %rax is the destination because it comes last, and the q suffix says 64-bit. Both listings show three loads from the array indexed by RSI scaled by 8, summed in RAX, which is the C function exactly. If you can read one listing, the second is a check on your reading.

Seeing both from one binary

objdump prints either syntax from the same object, so you can learn by comparing:

Shell
objdump -d --no-show-raw-insn sum.o
objdump -d --no-show-raw-insn -M intel sum.o

GDB defaults to AT&T and switches with set disassembly-flavor intel. perf annotate accepts --asm-raw and -M intel. So whichever tool shows you code, you can ask it for the dialect you read faster, and check your translation against its output.

Choosing a syntax for your own code

The notation matters less than being consistent inside a file. These are the situations and what to pick.

SituationChooseWhy
Writing code that lives in a GCC or Linux kernel treeAT&TMatches the rest of the tree, shares macros and CFI with compiler output
Following the Intel manuals or most online tutorialsIntel (NASM)The manual's examples copy straight in
Inline assembly in C with GCCAT&T by default, or -masm=intel for the whole fileExtended asm templates assume one dialect per translation unit
Writing code for Windows with MASMIntel (MASM syntax)MASM is Intel-style with its own directives
Reading a disassembly in a debuggerWhichever you read fastestThe tools can print either
Teaching beginnersIntelFewer symbols per instruction and destination-first order matches =
Porting between toolchainsKeep the source dialect, change the assemblerRewriting syntax and logic together hides bugs

If you work in a Linux codebase long enough, you will end up reading AT&T whether you like it or not, because that is what perf, kernel oops disassembly and most compiler explorer defaults use. A comfortable plan is to write in Intel, read AT&T with the six rules, and let the debugger translate when the rules slip.

Common slips and how to spot them

A few patterns reveal that someone is reading one dialect as the other. An instruction like mov $0x10, %rax read as Intel looks like a move from $0x10 into %rax with the order mixed up, but the % and $ give it away: if any operand has either prefix, it is AT&T and the destination is last. An instruction like sub rsp, 8 has no prefixes and the destination first, so RSP decreases by 8. Reading subq $8, %rsp as "subtract RSP from 8" instead of "RSP minus 8" is the most common beginner error, and it is cured by remembering that the last operand is always what changes.

A comparison that seems backwards in AT&T is usually correct. cmpl $10, %eax followed by jg jumps when EAX is greater than 10, because the test is eax - 10. Written in Intel, it reads cmp eax, 10, and jg jumps if EAX is greater than 10. The AT&T operand order is only confusing if you read it left to right as a sentence.

Memory operands with only a displacement are another source of mistakes. movl 0x601040, %eax in AT&T loads from the absolute address 0x601040, not the immediate value, because there is no $. The Intel spelling mov eax, dword ptr ds:0x601040 makes the dereference visible, and GDB prints exactly that form. If an AT&T line has a number with no $ in an operand slot, it is an address.

Also inToolchains
Share

Keep reading

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.