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
2 answers

What does "comparison is for a two’s-complement ‘>=’" mean?

I am learning assembly language and got stuck on this point. This is a problem from book "Computer System" chapter 3. The problem description is: 1st part of the problem 2nd part of the problem Look at questions A, B and C. A. cmpl %eax, %edx setl…
-1
votes
2 answers

How do I solve the error: Segmentation fault(core dumped) in my code? AT&T syntax

I've been looking for hours, and i can't find the mistake in my code. The program seems to exit at the "opadd" tag. I am using x86_64 on Linux, with AT&T syntax. The program takes as input a string of characters, for example, "2 3 add 4 mul", and…
Very Nice
  • 29
  • 4
-1
votes
1 answer

How does AT&T assembler behave when the operator width does not match the register width?

I am doing some research into x86 assemblers, and came across this wikipedia article. It notes that Intel syntax assemblers infer the width of the instruction/operand from the register width. AT&T syntax assembly mnemonics postfix a letter to the…
FreelanceConsultant
  • 13,167
  • 27
  • 115
  • 225
-1
votes
1 answer

Understanding Instruction Encoding?

I used a website to encode this: movw $8, 4(%r8d,%esi,4) and got: encoding (hex): 67 66 41 C7 44 B0 04 08 00 Thanks to you I nearly understand everything except 2 small points: Here we are moving 2 bytes immediate to 4 bytes address. They used C7…
user16566250
-1
votes
1 answer

Caller - Caller Saved Registers and Calling Conventions in Assembly?

I was reading about call conventions in Assembly x86-64 (AT&T) and have few questions: Does the caller need to backup all caller saved regiters even those which the called function won't change? Or we always backup all of them Same question…
user16385268
-1
votes
1 answer

This is the assembler code for a function, I did not quite get the meaning and the result of these two lines

These are the two line of assembler code. 0x0000000000400e8e <+34>: mov -0x8(%rbx),%eax 0x0000000000400e91 <+37>: add -0x4(%rbx),%eax The following is the whole assembler code and the printed register, where the arrow on the left…
-1
votes
3 answers

(Assembly) behavior of trying to load data into registers that cannot fit it?

I am learning assembly right now, and was just wondering if anyone could clarify the behavior of trying to move data into a register that cannot fit it. For example, suppose we had (on x86, AT&T syntax): movl $0xff00abcd, %ax Where %ax is the…
tmako
  • 349
  • 2
  • 9
-1
votes
1 answer

x86 Assembly Programming (GAS Syntax): How to get the nth bit of a variable stored in a register

I am trying to get the 5th bit of a variable stored in the EDX register (Intel x86 Assembly using GAS or AT&T syntax) and move it to the ESI register. However, when I execute my program, I get the following error: /tmp/SASM/program.asm:54: Error:…
Adam Lee
  • 436
  • 1
  • 14
  • 49
-1
votes
1 answer

What cmpl $0x1, -0x18(ebp) does in AT&T?

So I have a line that does logical compare like: cmpl $0x1, -0x18(ebp) . After this it jumps if this is equal, but what exactly does that -0x18(ebp) do?
aurora
  • 60
  • 1
  • 10
-1
votes
1 answer

Value of rbp changing after jumping into a new function

I have the following assembly program: .globl main main: push %rbp mov %rsp, %rbp movb $8, -1(%rbp) movw $30, -4(%rbp) mov -1(%rbp), %rax add -4(%rbp), %rax call func pop %rbp ret func: push %rbp mov…
samuelbrody1249
  • 4,379
  • 1
  • 15
  • 58
-1
votes
1 answer

Delay when running asm program with named variables

I have the following program to multiple two numbers: .globl main main: # Store the two numbers temporarily in ebx, ecx mov $7, %ebx mov $14, %ecx # clear out eax and add ebx (7) to it ecx (14) times mov $0, …
David542
  • 104,438
  • 178
  • 489
  • 842
-1
votes
1 answer

Linux Assembly Creating File Has A Name Size Limit?

I am trying to create a file in 32 bit assembly, however when the file is created the name is constrained to only four characters. I am not sure why this happens. here is my code; .section .data .equ SYS_WRITE, 4 .equ SYS_CREAT, 8 .equ SYS_OPEN,…
USER149372
  • 103
  • 2
  • 7
-1
votes
1 answer

GDB: until command stops where?

After running the program in gdb and disas command: 0x0000555555556692 <+0>: sub $0x18,%rsp 0x0000555555556696 <+4>: mov %0x28,%rax 0x00005555555566da <+13>: jmpq *%rax if i use (gdb) until *0x000055555555669f which is line…
-1
votes
3 answers

Assembly language meaning of two values in src or destination

For example, what is the difference between cmpl $0x7, 0x8(%rsp) and cmpl $0x7, (%rsp) Also what is the difference between cmp and cmpl?
-1
votes
2 answers

I'm confused about this arithmetic operators

I was trying to do this arithmetic operation in assembly but i was getting the wrong answer every time, not sure how exactly I'm suppose to do it These questions are from a textbook, and i do have the answers but trying to understand how to get that…
user12103280