AT&T Syntax is an assembly syntax used in UNIX environments, that originates from AT&T Bell Labs. It is descended from PDP-11 assembly syntax.
AT&T Syntax is an assembly syntax used mostly in UNIX environments or by tools like gcc that originated in that environment. GNU (gcc/binutils) chose AT&T syntax for compatibility with AT&T Bell Labs' Unix assembler syntax for 386. That in turn based its syntax design on the PDP-11 PAL-11 assembler. (See also: Questions about AT&T x86 Syntax design and What was the original reason for the design of AT&T assembly syntax?)
It's used by the GNU assembler, and some compatible tools like clang's built-in assembler. These tools all also use GNU assembler directives like .globl main and .byte 0x12 instead of db 12h. See the GAS manual.
Most tools that default to AT&T syntax have options to use MASM-like GNU Intel Syntax. gcc -masm=intel -S or objdump -drwC -Mintel. Or in GAS, .intel_syntax noprefix is a directive. See the intel-syntax tag wiki.
See also the x86 tag wiki for more about the x86 architecture and assembly in general. See the inline-assembly tag wiki for more about GNU C inline asm.
x87 syntax design bug / incompatibility with Intel syntax:
AT&T syntax reverses the mnemonics for fsubr and fsub, and other non-commutative x87 instructions like fdivr, when the destination is %st(i). See the GAS manual entry. Tools like objdump -d that disassemble in AT&T syntax are also compatible with this mnemonic -> opcode mapping. See also Objdump swapping fsubrp to fsubp on compiled assembly?
Modern version of objdump -d -Mintel use the Intel-syntax interpretation of the mnemonics as expected. (Editor's note: I seem to recall older versions of objdump and/or GAS in Intel-syntax mode still using the AT&T bug-compatible mnemonics.)
Syntax details
Operands are in destination-last order, the reverse of Intel syntax (used in Intel/AMD manuals). For example pshufd $0xE4, %xmm0, %xmm1 shuffles xmm0 and puts the result into xmm1. (Intel syntax pshufd xmm1, xmm0, 0E4h. To translate to/from Intel syntax, always reverse the list of operands.
Register names are prefixed with %, and immediates are prefixed with $. Operand-size is indicated with a b/w/l/q suffix on the mnemonic, but is optional if it's not implied by a register operand, the same way that dword or dword ptr is optional in NASM. Addressing modes use a totally different syntax, disp(base, idx, scale)
Examples:
sub $24, %rspreserves 24 bytes on the stack.mov foo, %eaxis a load from the address of symbolfoo.mov $foo, %raxputs that address in%rax(mov-imm32)lea foo(%rip), %rax(64-bit mode only) RIP-relative addressing mode for PIC (position-independent) code. (How to load address of function or label into register in GNU Assembler and what does "mov offset(%rip), %rax" do?)movabs $0x123456789ABCDEF, %raxthe imm64 or 64-bit absolute memory address forms ofmovuse themovabsmnemonic in AT&T syntax.imul $13, 16(%rdi, %rcx, 4), %eax32-bit load fromrdi + rcx<<2 + 16, multiply that by 13, put the result in%eax. Intelimul eax, [16 + rdi + rcx*4], 13.addb $1, byte_table(%rdi)increment a byte in a static table. (disp32+base addressing mode, so this is technically not an indexed addressing mode). Operand-size suffix is mandatory here, because neither operand is a register to imply a size.addl $1, dword_table(, %rdi, 4)increment a dword in a static table. (disp32 + scaled-index addressing mode with no base register).movswl (%rdi), %eaxsign-extending load from word (w) to dword (l). Intelmovsx eax, word [rdi]. AT&T needs different mnemonics for each source size of movzx / movsx. What does the MOVZBL instruction do in IA-32 AT&T syntax? and what does movsbl instruction do?.cltq=cdqein Intel,cltd=cdq. They (and related instructions for other sizes) sign extend within eax/rax or from eax into edx:eax (orraxintordx:rax). The GNU assembler accepts the more-readable Intel mnemonics where the within-rax version always ends withe(except forcbw). See What does cltq do in assembly?.
- NASM Vs GAS (Practical differences)
- What I Dislike About GAS explains AT&T vs. NASM and MASM syntax with examples, pointing out some reasons that some people find it unpleasant to write by hand.
- http://en.wikibooks.org/wiki/X86_Assembly/GAS_Syntax.
- http://www.imada.sdu.dk/Courses/DM18/Litteratur/IntelnATT.htm More about Intel vs. AT&T syntax.
Canonical Q&As:
- x64: Why does this piece of code give me "Address boundary error"
mov 1, %regis a load from absolute address 1 and faults.mov $1, %regis a mov-immediate. - What's difference between number with $ or without $ symbol in at&t assembly syntax? - use
mov $foo, %ecxto get an address in a register. - x86 assembly - printing a character given an ascii code (
mov $symbol, %ecxto set up for a write system call, notmov symbol, %ecx) - Assembly, x86: How to push a label to the stack? -
push $foonotpush foo