Questions tagged [att]

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 tag wiki.

See also the tag wiki for more about the x86 architecture and assembly in general. See the 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, %rsp reserves 24 bytes on the stack.
  • mov foo, %eax is a load from the address of symbol foo.
  • mov $foo, %rax puts 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, %rax the imm64 or 64-bit absolute memory address forms of mov use the movabs mnemonic in AT&T syntax.
  • imul $13, 16(%rdi, %rcx, 4), %eax 32-bit load from rdi + rcx<<2 + 16, multiply that by 13, put the result in %eax. Intel imul 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), %eax sign-extending load from word (w) to dword (l). Intel movsx 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 = cdqe in Intel, cltd = cdq. They (and related instructions for other sizes) sign extend within eax/rax or from eax into edx:eax (or rax into rdx:rax). The GNU assembler accepts the more-readable Intel mnemonics where the within-rax version always ends with e (except for cbw). See What does cltq do in assembly?.


Canonical Q&As:

1033 questions
-2
votes
1 answer

AT&T to Intel Syntax

I want to translate following lines from AT&T to Intel (nasm) : This is my AT&T-Code: .equ BUFFEREND, 1 .lcomm buffer, BUFFEREND cmpb $97, buffer And here is my Intel-Code: BUFFEREND EQU 1 buffer db BUFFEREND cmp BYTE [buffer],…
Shibumi
  • 635
  • 6
  • 17
-3
votes
1 answer

What is 'xorl' and 'imul' are used for in this assembly code? Can it be converted to c Code?

int func2(int x, int y) movl 4(%esp), %eax addl 8(%esp), %eax xorl $255,%eax imul 8(%esp), %eax sall $4, eax
Suleman
  • 1
  • 1
-3
votes
1 answer

Order In .data in x64 Assembly?

Giving the following assembly code I know that .data grows towards higher addresses so after running the code the memory looks something like: - - - - - - - - (var3 here and up) - - - - (var2 here and up) - - - - (var1 here and up) So when they ask…
Dan
  • 99
  • 6
-3
votes
1 answer

absolute physical memory reference

Consider a program that uses absolute physical memory references movl ($0x100), %eax movl ($0x104), %ebx movl %eax, ($0x104) movl %ebx, ($0x100) This program works fine when it is loaded at address 0x0, but not when it is…
-3
votes
2 answers

x87 double addition don't work

I defined an assembly function which takes three parameters (int, double, double) which should add two putted double value and return the result of this addition. And I don't know why the below code doesn't work: extern double ftaylor(unsigned int…
fingolfin
  • 77
  • 5
-3
votes
1 answer

assembly: how to extend a float to a double for sin function usage

The C version functions: float foo1 (float a, float b) { return sin(a) + b; } double sin(double x); double cos(double x); cos is for a later function. The task is to translate foo1 to assembly, but as you can see a is a float and sin expects…
Ajna
  • 115
  • 2
  • 9
-4
votes
1 answer

I need help understanding what some instructions mean

I am learning x86 assembly and have some problems with understanding some of the instructions. What does sub $0x10,%rsp mean, and why GCC copied this mov $0x0,%eax line two times? 0x0000000000001135 <+0>: push %rbp 0x0000000000001136…
Nazar
  • 3
  • 3
-4
votes
1 answer

Assembly instruction operand

What does the 40 in movq 40(%rdi), %rax mean? I see that the value (in other instructions automatically generated by gcc) is always a positive multiple of 8 (ie. 8, 16, 24, 32, ...) It is also always surrounded by () I also know that the () means…
sviamwvnb
  • 139
  • 1
  • 6
-4
votes
2 answers

x86 assembly multiply two 32 bit numbers

I am learning intel assembly language(att syntax) in my free time and I was just wondering how you can multiply two numbers lets say 5 and 2 together without using the mul command?
jack
  • 9
  • 1
  • 1
-4
votes
1 answer

How to declare local variables in macro asm of gas like decalaring it in macro asm with %local in macro asm of nasm or local in macro asm of masm?

the way to declare local variables in macro asm of nasm is like:%local old_ax:word,and the way to declare local variables in macro asm of masm is like:local old_ax:WORD,so what's the way to declare local variables in macro asm of gas?
linkerrors
  • 39
  • 6
-5
votes
1 answer

Confused how to read assembly instruction

I have some questions dealing with reading assembly instruction. I know the basic instruction syntax, but it gets confusing when some of the register comes with some address in front of it, or the question uses any of the strange instruction. Is…
shjnlee
  • 221
  • 2
  • 6
  • 20
-5
votes
3 answers

Learning Assembly Language

I am attempting to learn assembly language, but i need help with learning what each command's purpose is. Following is a program where they are used. push %ebp mov %esp,%ebp sub $0x10,%esp mov 0x8(%ebp),%eax add $0x1,%eax mov …
Tom Plutz
  • 11
  • 3
-7
votes
2 answers

ATT Assembly to C

Working on learning assembler and I have the following code I have to translate to C: pushl %ebp movl %esp, %ebp movl 12(%ebp), %eax imull $886836204, %eax, %edx movl 8(%ebp), %eax addl %edx, %eax addl $629084528, %eax popl …
1 2 3
68
69