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
12
votes
5 answers

trying to understand the assembly instruction: cltd on x86

I found the assembly instruction cltd by disassembling code on an Intel architecture. The description I found was, that it clears the %edx register, but I don't understand what happens.... can anyone explain what the command exactly does?
Muten Roshi
  • 493
  • 2
  • 5
  • 17
12
votes
2 answers

What is the ".s" suffix in x86 instructions?

When I disassemble the .text sections of some binaries using objdump (with both AT&T and Intel syntaxes), I sometimes see instructions with a .s suffix, for example: cmpb.s %bh,%ch, sbbl.s %edi,%edi, or adcb.s %bl,%dh. Does the .s suffix have a…
Peter Goodman
  • 438
  • 3
  • 12
12
votes
1 answer

x86 cmpl and jne

I'm tracing some x86 code for an assignment, and I was wondering what exactly "cmpl" does and how to predict whether or not the "jne" will be met. 80484bf: 83 7d f0 07 cmpl $0x7,-0x10(%ebp) 80484c3: 75 16 jne …
Richarizard
  • 131
  • 1
  • 1
  • 3
11
votes
2 answers

lea assembly instruction

I Just want to make sure I am reading this right: movl 12(%ebp), %edx leal (%edx, %edx, 4), %eax I read the first line as: edx = [epb + 12], and the second line as: eax = edx + edx*4 Can anybody clarify? Also, what if I had the following two…
Chris Dargis
  • 5,891
  • 4
  • 39
  • 63
11
votes
3 answers

NASM (Intel) versus AT&T Syntax: what are the advantages?

I'm going through the Intel processor documentation and writing some basic assembly code at the same time. I have both nasm and as (GAS) on my server and I understand the basic differences of both assemblers. In the long run: Focusing on which of…
user613857
11
votes
5 answers

Embed URL Link in SMS via PHP

Is there a way I can embed a URL link i.e. google in an SMS message send through [myphonenumber]@txt.att.net ? My mail configuration is set to "text/html" but the link shows up as un-clickable plain text in the…
sadmicrowave
  • 39,964
  • 34
  • 108
  • 180
11
votes
1 answer

The difference between mov and movl instruction in X86? and I meet some trouble when reading assembly

Recently, I read some books about computer science. I wrote some C code, and disassembled them, using gcc and objdump. The following C code: #include #include int dojob() { static short num[ ][4] = { {2, 9, -1, 5}, {3,…
Ding Xin
  • 307
  • 1
  • 3
  • 11
11
votes
2 answers

what does "mov offset(%rip), %rax" do?

Does rax get offset plus the address of this instruction, or the next? From a microcode point of view it might be easier if the answer was the next instruction.
Bing Bang
  • 524
  • 7
  • 16
11
votes
1 answer

What does JS do in Assembly x86?

cmp %al, %cl js x I'm confused on what the js (jump on sign) is doing. Is it saying that if al is positive and cl is negative vice versa then jump? Also, what happens if %cl is 0?
user3128376
  • 974
  • 6
  • 17
  • 40
11
votes
1 answer

Why does switching from AT&T to Intel syntax make this tutorial segfault using GAS?

I'm working through some of the tutorials on http://www.ibm.com/developerworks/linux/library/l-gas-nasm/index.html to familiarize myself with x86/x64. This tutorial code compiles and runs without a hiccup using the provided code, which uses AT&T…
Alex
  • 599
  • 1
  • 4
  • 16
10
votes
2 answers

what does "outb" in AT&T asm mean?

I am reading some code of Linux. The keyboard.S has something like outb %al,$0x61 and inb $0x61,%al I think the pending 'b' means 'byte', but i still cannot find what these instructions mean.
onemach
  • 4,265
  • 6
  • 34
  • 52
10
votes
1 answer

Passing a pointer to an assembly function

I'm rather new to assembly programming. I'm using the x86 platform with GCC (Linux). I have a function that I want to call from C as: myfunc ( unsigned char * s1, unsigned char * s2, int someint ); The function will take the s1 and s2 memory…
raindog308
  • 772
  • 1
  • 10
  • 20
10
votes
2 answers

How cmp assembly instruction sets flags (X86_64 GNU Linux)

Here is a simple C program: void main() { unsigned char number1 = 4; unsigned char number2 = 5; if (number1 < number2) { number1 = 0; } } So here we are comparing two numbers. In assembly it will…
abs
  • 384
  • 2
  • 4
  • 14
10
votes
3 answers

what is the difference between a label and a function in assembly

have been following an assembly tutorial on youtube here through AT&T syntax. I have just learned about declaring(if that's the correct term here) a function with the .type directive, such as: .type MyFunction, @function Now I can define my…
user3118363
  • 337
  • 4
  • 13
10
votes
2 answers

Pointer Deferencing in x86 Assembly Code

I'm reading my textbook and it has code for a swap function: In C: int exchange(int *xp, int y) { int x = *xp; *xp = y; return x; } In x86 Assembly with annotations: // xp is at %ebp + 8, y at %ebp + 12 movl 8(%ebp), %edx // get xp movl…
cheng
  • 1,264
  • 2
  • 18
  • 41
1 2
3
68 69