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

In assembly, how do I store the input from the scanf call?

input: .asciz "%ld"... subq $8, %rsp eaq -8(%rbp), %rsi movq $input, %rdi movq $0, %rax call scanf I want to store the input given from the scanf and modify it, and then print it using call printf How could I approach this problem?
grumps
  • 1
  • 1
-1
votes
1 answer

How to use pointers with registers in assembly?

I'm working on a project where I have to debug a "binary bomb" by looking at its assembly code to help us learn about assembly. This one line is confusing me. cmp (%esi),%eax je 80486d1 I "solve" the bomb when the code jumps due…
A. R.
  • 49
  • 1
  • 5
-1
votes
1 answer

How does assembly subq set flags for a branch like JLE? Which register has to be greater for it to jump?

If we do something like: subq %rbx, rax jle somewhere Does this mean jump if rbx is less than or equal to rax or rbx is greater than or equal to rax?
user8782165
-1
votes
1 answer

32 Bit Unsigned Integer to Hexadecimal String - Incorrect Output

I'm struggling to convert a given integer into hex. I'm not getting correct output and it's likely due to incorrect shifting of bits. The algorithm I tried was to start at the 3rd position The code: .globl hex_str hex_str: movl $48,…
-1
votes
1 answer

AT&T assembly adding bytes

I need some help in AT&T assembly. I've load some data into memory like below (hex and dec) (gdb) x/8xb &buffer_in 0x8049096: 0x03 0x02 0x10 0x27 0xe8 0x03 0x64 0x00 (gdb) x/8db &buffer_in 0x8049096: 3 2 16 …
Barcys
  • 1
  • 1
  • 3
-1
votes
1 answer

can someone explain me the stack of this code?

English it's not my first language so if i spell wrong some words sorry. I've some trouble with the stack, all codes that i will put here works perfectly. This code for example it's easy and i understand the stack of it. .globl f f: …
CivilEngine
  • 47
  • 1
  • 5
-1
votes
1 answer

Iterate stack in AT&T x64 assembly

I have to iterate through the stack to temporary move the values of the words to a register, something like this: movq ((i - 3)*8)(%rsp), %esi or movq %rcx, %rbx # where %rcx is the counter subq $3, %rbx …
Ralph
  • 145
  • 1
  • 2
  • 8
-1
votes
1 answer

Segmentation error upon calling scanf in x86_64 AT&T

I am quite new to Assembly and I am trying to create a program that uses scanf to receive a number from the user. It then outputs "Result: (the number)" I keep getting a segmentation error upon running the code. This is the code I have got…
-1
votes
2 answers

".int" vs ".byte" for creating an array on GNU assembler

I am at odds to understand why after initializing an integer array using .int doesn't work with movl however doing it with .byte works flawlessly. P.S. I'm using AT&T syntax just so that it is clear from the beginning Here's the code: .data …
AjB
  • 890
  • 13
  • 34
-1
votes
1 answer

x86 Assembly - Frequency of a character in a sentence

.data ch: .string "aeiou" #ascii char string: .string "This course is about encoding numbers and instructions into binary sequences and designing digital systems to process them." endofstring: .space …
Egyptian_Coder
  • 63
  • 1
  • 10
-1
votes
1 answer

Segmentation fault basic assembly

.text .global main // code for main main: push %r13 push %r14 push %r15 pushq $2 call show pop %r15 pop %r14 pop %r13 mov $0,%rax ret // code for show show: popq x pushq x popq gen lea…
Nik L
  • 1
  • 2
-1
votes
1 answer

how to convert 64bit number to string in x86 assembly?

I am looking for a way to convert 64bit number to a string (and possibly the other way around) using 32bit system. I'm not asking for code, just asking for some ideas.
sstefan
  • 385
  • 4
  • 15
-1
votes
1 answer

Android App internet access not working on AT&T network

I've created and deployed an android app on to the Google play store. Throughout the entire process of developing the app I never ran into any issues with connecting to my online database. Now that I've launched it on the play store I've started…
rpeck
  • 1
-1
votes
1 answer

How do I get a register to store an offset value in at&t syntax?

I am using this to write to the video memory (%es = 0xb800): movw $0x074b,%es:(0x0) However, what if I want the offset to be in %ax? I tried %es:%ax, or %es:(%ax), but nothing worked, and I kept getting errors. What am I doing wrong?
francisaugusto
  • 1,077
  • 1
  • 12
  • 29
-1
votes
2 answers

x64: How to do a relative jmp *%rax?

I want to encode a 64 bit relative jump to the address stored in %rax in x64 assembly. AFAIK, there is no opcode for this, so I calculate the corresponding absolute address for the relative address manually and then I do an absolute jump to the…
Daniel S.
  • 6,458
  • 4
  • 35
  • 78