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
22
votes
1 answer

A couple of questions about [base + index*scale + disp] and AT&T disp(base, index, scale)

The general form for memory addressing in Intel and AT&T Syntax is the following: [base + index*scale + disp] # Intel, including GAS .intel_syntax noprefix disp(base, index, scale) # AT&T My questions are the following: Can base and…
user4344762
19
votes
1 answer

mov instruction in x86 assembly

From what I've read about mov, it copies the second argument into the first argument. Then, what does this do? movl 8(%ebp), %edx It copies whatever is in edx to the first parameter of the function (since an offset of +8 from ebp is a…
hut123
  • 445
  • 3
  • 7
  • 14
19
votes
1 answer

What's the difference between 'push' and 'pushq' in at&t assembly

I've recently started my quest of obtaining a greater understanding as to how my computer works. My question is in regards to the differences between push and pushq. I'm aware that push writes a value to the stack and my assumption is that pushq…
user6090272
18
votes
2 answers

Assembling 32-bit binaries on a 64-bit system (GNU toolchain)

I wrote assembly code that successfully compiles: as power.s -o power.o However, it fails when I try to link the object file: ld power.o -o power In order to run on the 64 bit OS (Ubuntu 14.04), I added .code32 at the beginning of the power.s…
buweilv
  • 451
  • 1
  • 4
  • 18
18
votes
3 answers

Smart Bluetooth: GATT Vs. ATT - what are the differences between them?

Can anyone please define for me what are the differences between GATT and ATT? I didn't manage to understand. I know that they are both generic protocol to handle BLE services. but didn't really understand it. Please explain. Thanks!
RRR
  • 3,937
  • 13
  • 51
  • 75
17
votes
1 answer

How to load address of function or label into register

I am trying to load the address of 'main' into a register (R10) in the GNU Assembler. I am unable to. Here I what I have and the error message I receive. main: lea main, %r10 I also tried the following syntax (this time using mov) main: movq…
user11810714
16
votes
3 answers

The difference between cmpl and cmp

I am trying to understand assembly to be able to solve a puzzle. However I encountered the following instructions: 0x0000000000401136 <+44>: cmpl $0x7,0x14(%rsp) 0x000000000040113b <+49>: ja 0x401230 What I think it's…
Sarah cartenz
  • 1,313
  • 2
  • 14
  • 37
16
votes
1 answer

Is there a complete x86 assembly language reference that uses AT&T syntax?

Ideally there would be a version of Intel's Software Developer's Manuals written in AT&T syntax, but I would be happy to find anything that is close enough.
sigjuice
  • 28,661
  • 12
  • 68
  • 93
15
votes
1 answer

Newbie asm: where is the call code?

I wrote this simple kernel module: #include // for printk() int init( void ) { printk( "n Kello, everybody! nn" ); return 0; } void exit( void ) { printk( "n Goodbye now... nn" ); }…
paulAl
  • 949
  • 2
  • 10
  • 17
15
votes
3 answers

What is the jmpq command doing in this example

We are using gdb debugger to read assembly functions. In assembly, we have the following instructions: mov 0xc(%rsp),%eax jmpq *0x402390(,%rax,8) At memory location *0x402390 we have the value 0x8e. In register rax, we have the second integer…
MichaelGofron
  • 1,310
  • 4
  • 15
  • 29
14
votes
3 answers

Commenting syntax for x86 AT&T syntax assembly

The Intel syntax has comments using the semicolon. When I switched to AT&T, it actually tried to interpret the comments. What is the comment syntax for AT&T assembly?
ihsoy ih
  • 1,008
  • 2
  • 10
  • 20
12
votes
4 answers

What does the bracket in `movl (%eax), %eax` mean?

I have googled enough but could not figure out what the bracket () means. Also, I see some syntax as movl 8(%ebp), %eax Could some someone suggest me some good reference? I have not been able to find any in the top 20 results from Google.
Lord Loh.
  • 2,437
  • 7
  • 39
  • 64
12
votes
1 answer

What does movslq do?

I have trouble finding out what movslq instruction does. Google isn't very helpful and there is no such instruction on this list. Here I have read that MOVSLQ is move and sign-extend a value from a 32-bit source to a 64-bit destination. I…
ibodi
  • 1,543
  • 3
  • 21
  • 40
12
votes
2 answers

Why is GNU as syntax different between x86 and ARM?

I've just started learning ARM assembly and I don't understand why the GNU as syntax is not the same than for x86*. As the directives are the same, I would have expected everything to be like x86* except the instructions themselves, but instead, I'm…
Benoît
  • 3,355
  • 2
  • 29
  • 34
12
votes
1 answer

Defining Bytes in GCC Inline Assembly in Dev-C++(.ascii in AT&T syntax on Windows)

The code below is just showing a Message Box on the screen. The addresses are hardcoded to facilitate: int main () { asm("xorl %eax, %eax \n" "xorl %ebx, %ebx \n" "xorl %ecx, %ecx \n" "xorl %edx, %edx…
jyz
  • 6,011
  • 3
  • 29
  • 37
1
2
3
68 69