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

Arbitrary number of parameters in Assembler (x86, att)

I'm creating a function with the following signature: int function_test (char *something, ...); Let's suppose that on *something there's something that will allow me to know how many parameters were passed (just like printf does with '%'). So I…
francisaugusto
  • 1,077
  • 1
  • 12
  • 29
-1
votes
1 answer

mod_rewrite not working as expected on AT&T shared hosting service

New to mod_rewrite and have searched the net and Apache docs with no results so far. I'm trying to test the functionality of mod_rewrite on an AT&T Web Services host, using the following rewrite rule in an .htaccess file inside a…
-1
votes
2 answers

x86 assembly gcc calling conventions esp register

Documentation says that when assembly method is called first argument should be at 4(%esp). If so is the second argument at 8(%esp)? I really don't get the gnus at&t assembly syntax so what is this following code equal to in intel…
The amateur programmer
  • 1,238
  • 3
  • 18
  • 38
-1
votes
3 answers

AT&T assembly: how to mult a double by 2 without local variable. Shift Double?

[homework]: try to do exactly what the C code says. The full functions code with C version commented: /* double f(double x) { return x * 2.0; } double foo (int a[], double b[], int n) { int *pint; double *pdouble; double sum =…
Ajna
  • 115
  • 2
  • 9
-1
votes
1 answer

What does lea 0xY(%esp), %esi do?

I dont understand what this code will do lea 0x13(%esp), %esi %esp is a stack pointer, %esi is index register. Is 0x13 offset?
JohnDow
  • 1,242
  • 4
  • 22
  • 40
-1
votes
1 answer

Last stretch of rounding function in ASM

What I essentially have to do is make what is in Main work. I'm on my last stretch of this assignment (which will likely take just as long as it did for me to get here) I'm having trouble figuring out how to pass the roundingMode that is passed to…
Ranger Skip
  • 105
  • 8
-1
votes
1 answer

Simplifying Assembly Instruction

I'm trying to convert the following code into a single line using leal. movl 4(%esp), %eax sall $2, %eax addl 8(%esp), %eax addl $4, %eax My question is of 3 parts: Does the '%' in front of the register simply define the following string as a…
user3421751
  • 209
  • 1
  • 2
  • 9
-1
votes
1 answer

assembly language tricky memory addresses

We are given the prompt (using AT&T ASM) eax = A ebx = B ecx = &X edx = &Y I understand that (%eax) would grab the data in the memory location at A, but what would doing (%edx) grab? Say for example the call movl (%edx),…
havak5
  • 714
  • 1
  • 6
  • 20
-1
votes
1 answer

Binary Bomb Assembly Language Assignment

Like many people here, I have been given the task to do the bomb lab. I have been able to do the first 3 rather easily, but this phase escapes me. I have determined that the answer includes 2 answers in the form of %d %d, but I have been unable to…
soxluvr23
  • 13
  • 1
  • 3
-1
votes
1 answer

Assembly AT&T x86 read from file

I'm trying to write a piece of code that will display the contents of a txt file. I only have numbers stored in the new file, one number per line (%d \n). Currently the code looks like this: movl $0 , 320(%ebp) #a pre reserved location on the stack…
Thijser
  • 2,625
  • 1
  • 36
  • 71
-1
votes
1 answer

Porting 16-bit DOS x86 assembly to 32-bit Linux x86 assembly

I found code in 80836 DOS assembly that I'd like to port to 32-bit Linux assembly, using AT&T syntax. I found site that explains some differences but only about registers. EX: cmp al, 'A' -> cmp 'A', %al So I got problems converting following…
-2
votes
1 answer

What is %rax initialized to?

hybrid.s .section .text # specifices the beginning of the 'text' or code section .global collatz # makes the name 'collatz' visible to the linker collatz: # int collatz(long long n) { ret # return hybrid.c #include
Sebastian Nielsen
  • 3,835
  • 5
  • 27
  • 43
-2
votes
1 answer

What opt in rate can be achieved with Apple’s iOS14 ATT prompt?

As of iOS14 Apple require a permission prompt to use IDFA for advertising. Can anyone who has implemented the App Tracking Transparency (ATT) framework already share rough percentages of users who tap Allow vs. Don’t Allow? Some articles have…
Henry Heleine
  • 673
  • 2
  • 9
  • 28
-2
votes
1 answer

operand size for "out"

I'm using the GAS assembler. I'm trying to write to the I/O port 0x20, I do it like this: outb $0x20, $0x20 But I get this error: Error: operand type mismatch for out What am I doing wrong?
-2
votes
1 answer

Don't line break in shell after executing asm programm. [AT&T]

Like in the title said the asm programm should not automatically break a new line after executing it. My programm is a simplified version of the "echo" command in linux. It prints the arguments given by the user. If the users first argument is '-n'…
plako
  • 11
  • 2