Blog / Development / Assembly

GAS: Why AT&T Syntax Is Not as Bad as It Looks

Source, destination and register prefixes – logical rather than mysterious.

The first encounter with GNU Assembler often involves percent signs, dollar signs and an apparently reversed operand order. Behind those rules is a remarkably consistent system.

By Tom Heinrich
GNU Assembler, GAS, AT&T-Syntax, x86-64
Comparison of AT&T and Intel syntax in GNU Assembler

GNU Assembler, usually called GAS, is a core part of the GNU toolchain. You encounter it when writing assembly directly, reading compiler output or debugging with tools such as GDB and objdump.

On x86 systems, GAS traditionally uses AT&T syntax. It initially looks unusual, especially to readers familiar with Intel syntax. After learning a few rules, it becomes readable and very explicit.

In short: AT&T syntax is not more complicated. It simply makes different choices about operand order, register notation and size information.
1

Source first, destination second

The most visible difference from Intel syntax is the order of operands. AT&T writes the source first and the destination second.

The instruction movl %eax, %ebx therefore means: copy the 32-bit value from %eax to %ebx.

The same operation in two notations

# AT&T syntax: source, destination
movl %eax, %ebx

; Intel syntax: destination, source
mov  ebx, eax

Both lines describe the same machine operation. Only the textual representation differs.

FeatureAT&T syntaxIntel syntax
Operand orderSource, destinationDestination, source
Register%eaxeax
Immediate value$11
SizeSuffix: b, w, l, qoften inferred or stated with keywords
Comment# comment; comment
2

Registers begin with a percent sign

Registers use the % prefix: %rax, %eax, %al or %rsp.

The prefix makes it immediately clear that the token is a register rather than a symbol or memory address.

3

Immediate values begin with a dollar sign

The dollar sign identifies a literal value. $1 means the number 1. Without it, the expression may be interpreted as a memory operand.

Adding an immediate value to a register

# eax = eax + 1
addl $1, %eax
4

The suffix describes the size

Many x86 instructions use a suffix in GAS: b for byte, w for word, l for 32 bits and q for 64 bits.

movb, movl and movq therefore reveal how much data is moved.

5

Memory operands use parentheses

(%rax) accesses memory at the address stored in %rax. More complex addressing follows:

displacement(base, index, scale)

For example, 8(%rax,%rcx,4) means 8 + rax + rcx × 4.

6

Labels remain surprisingly normal

A name followed by a colon defines a label, and jump instructions refer to it.

A small loop

.section .text
.global _start

_start:
    movl $1, %eax
    movl $1, %ecx

.Lloop:
    cmpl $10, %ecx
    jg   .Lend
    addl %ecx, %eax
    incl %ecx
    jmp  .Lloop

.Lend:
    movl $60, %eax
    xorl %edi, %edi
    syscall

The example combines labels, immediate values, registers and source-destination order in one small program.

7

Why compiler output often uses AT&T syntax

GCC, objdump and GDB use AT&T syntax by default in many Linux environments. Reading it makes compiler output, disassembly and crash analysis much easier.

8

Why this matters for t8core

t8core applications are not written entirely in assembly. GAS still matters when compiler output is inspected, performance is analysed, system calls are studied or optimized builds are debugged.

For OCR, image processing and sensitive document workflows, it matters not only that code works, but also which instructions, memory accesses and system transitions are actually generated.

Important point

AT&T syntax is not a different kind of assembly. It is another notation for the same machine instructions.

Summary

  • The source comes before the destination
  • Registers begin with %
  • Immediate values begin with $
  • Suffixes show operand size
  • GAS is common throughout the GNU and Linux ecosystem

Conclusion

AT&T syntax only feels strange until its few basic rules become familiar. After that, it is a useful tool for reading compiler output, debugging and understanding what the CPU actually executes.

You do not need to treat it as a religious preference. Being able to read it is enough. The CPU does not care about syntax debates anyway. It receives bytes.