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

In the Assembly language, what does the 'l' in "movl" stands for?

I understand that movb is move byte, movw is move word, movq is move quad word. movl is move double word, but what does the l stands for?
chunjiw
  • 1,093
  • 9
  • 20
-2
votes
1 answer

How to open a file in assembly x86

I am trying to open a local file ('flag' in a target file) in assembly in order to write an exploit script output the flag. However, I am getting the error: "target: Too long input: Success" when trying to open the file. This is my code to load…
s.hu
  • 37
  • 1
  • 7
-2
votes
1 answer

GNU 64-bit assembly adding functin

When we have add %rbx, %rax Does this mean add the value of rbx to rax or add the value rax to rbx? If for example rbx=3 and rax=6, after the add %rbx, %rax, what will be the values of %rax and %rbx? GNU x64 assembler syntax please!
Dan
  • 139
  • 1
  • 8
-2
votes
1 answer

Why does GCC generate a "mov 0x8,%edx" instruction that causes a crash?

I have a function which is declared like this: void tesysLog(W16 uid, char *file, int line, int level, W16 state, W16 event, int error, char *format, ...) There is another func which will call tesysLog above, for example,: tesysLog(253,…
Jeff.Lu
  • 574
  • 3
  • 16
-2
votes
2 answers

What's the difference between 0(%eax) and (%eax)?

If there is an address of a char array in eax, what's the difference between 0(%eax) and (%eax)?Or are they the same, both refer to the first element in the array?
vingin
  • 11
  • 1
-2
votes
1 answer

Scanf a char pointer in Assembly

So I have a task to do, which requires from me to scanf a char* in assembly. I tried this code: .data INPUT_STRING: .string "Give me a string: " SCANF_STRING: .string "%s" PRINTF_STRING: .string "String: %s\n" .text .globl main .type…
minecraftplayer1234
  • 2,127
  • 4
  • 27
  • 57
-2
votes
3 answers

Porting from Windows to Linux. Assembler command translation

I have recently started learning porting from Windows to Linux. I've been translating program from Intel syntax to AT&T syntax also converting it from x32 to x64. And since I'm new enough to assembler and especially AT&T I've faced some troubles…
Random Guy
  • 1,095
  • 16
  • 29
-2
votes
1 answer

Learning Assembly num function

So I'm learning Assembly and i have come across this code: movl num(,%eax,4), %eax Can someone explain what that num() function is?
Newb18
  • 167
  • 2
  • 11
-2
votes
1 answer

Read & write and integer in assembly ATT

I have been trying to to read an integer from stdin and after write it in stdout, but the only thing that I accomplish is writing a simply hello world. This is the code that I have: .global _start _start: push %ebp movl %esp,%ebp subl $4,%esp…
Miguel
  • 1
  • 5
-2
votes
1 answer

Write this exercise in less than 4 lines assembly AT&T

we start with a 32 bit code e.g: "AA BB CC DD" (little endian) we want "AA DD CC BB" as end result (big endian). I've managed to write it in 8 lines, with %ebx as the entry and %ecx as the exit. The teacher mentioned it was possible to write this in…
P. Diddy
  • 21
  • 1
-2
votes
1 answer

Assembly less than

Im trying to recreate a "less than" function in AMD64 assembly. Like in this case I wanna return 1 if the parameter in %rdi is less then 3. .globl f .type f, @function f: xor %rax, %rax movq %rdi, %r10 cmpq…
Jakob Abfalter
  • 4,980
  • 17
  • 54
  • 94
-2
votes
1 answer

assign memory location to register assembly

Let's say for example I have four specific memory addresses that each hold a 32-bit integer. How would you use assembly language to take the address and assign it register %eax? Would it be movl 0x12AED567, %eax?
Sajay Shah
  • 21
  • 1
  • 7
-2
votes
1 answer

Sieve of Eratosthenes in AT&T Assemby

I have written a simple program in C to find all prime numbers within a given range using Sieve of Eratosthenes. In school, we are currently learning assembly in a class, but I can't figure out how to write the three loops. I have somewhat figured…
erikst
  • 23
  • 5
-2
votes
1 answer

Calling printf and scanf in AT&T assembly

I've got the following code: .align 32 .data input1: .string "Give short: \n" input2: .string "Give char: \n" arg1: .string "%hu" arg2: .string "%c" output1: .string "%hu\n" output2: .string "%c\n" short: .short 1 char: .byte 1 .global…
trnks_
  • 45
  • 1
  • 7
-2
votes
1 answer

Converting decimal to binary in assembly x86

I'm trying to write decimal to binary converter and for some numbers it works and for others it doesn't. 0 - 8 numbers works fine, but when I input 9 it displays 101. SYSEXIT = 1 SYSREAD = 3 SYSWRITE = 4 STDOUT = 1 STDIN = 0 .bss …
Bartosz Karpiński
  • 467
  • 1
  • 5
  • 15
1 2 3
68
69