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

Segfault on function termination

I have a function written in 64 bit x86 assembly (AT&T syntax for gcc and GAS) which performs some SSE2 operations. I've checked the result by using gdb with disassembly and looking at the register values, so I know it's producing the correct…
0
votes
1 answer

ATT assembly language arithmetic

Address Value Register Value 0x100 0xFF %eax 0x100 0x104 0xAB %ecx 0x1 0x108 0x13 %edx 0x3 0x10C 0x11 Instruction Destination …
ShadyBears
  • 3,955
  • 13
  • 44
  • 66
0
votes
1 answer

How to compute switch case values from assembly code?

ATT syntax. I'm trying to understand a practice problem we talked about in class. We were given the following partial assembly code for a switch statement: movl 8(%ebp), %eax addl $2, %eax cmpl $6, %eax ja .L2 jmp *.L8(,%eax,4) //rest of…
amorimluc
  • 1,661
  • 5
  • 22
  • 32
0
votes
3 answers

What is this piece of assembly code into C?

ATT syntax. I'm trying to understand what the following piece of assembly code does: movl 8(%ebp), %edx movl $0, %eax testl %edx, %edx je .L7 .L10: xorl %edx, %eax shrl %edx jne .L10 .L7: andl $1, %eax It's supposed to be the body of a…
amorimluc
  • 1,661
  • 5
  • 22
  • 32
0
votes
2 answers

Translating a while statement from c to assembly using yacc

I'm trying to write a yacc source file for a program that will convert a simple while statement from C language (let's say ANSI 89) to assembly at&t. The following is my grammar, the central part of yacc file. %% while_statement : 'w' 'h' 'i'…
0
votes
1 answer

Snake game in assembly

I'm trying to make a small IA32 game(AT&T), the problem I'm facing at the moment is I don't know how/where to store the snakes body and the "apples" to be able to check for collisions. The snakes size is constantly increasing so the container…
ogward
  • 1,183
  • 4
  • 13
  • 18
0
votes
1 answer

Copying the value of a pointer to another new pointer in Assembly

Update: I'm allowed to use strcpy in my code. I'm trying to write an implementation of strdup in x86 assembly (att syntax), converting the code in C to code in Assembly. Code in C: char* func( int x, char* name){ namestr = (char *) malloc(…
rlhh
  • 893
  • 3
  • 17
  • 32
0
votes
2 answers

'C' appearing as 2 different values?

I'm trying to compare 2 different char in assembly(calling assembly function in C program). One of the char belongs to a struct and the other is passed in when calling the function. struct node { void *previous; void *next; …
rlhh
  • 893
  • 3
  • 17
  • 32
0
votes
2 answers

Loop over function args on the stack, using a register as an index for ESP?

Just a short question. Anyone knows if there is any way that I can do this in assembly? movl $4, %ebx movl (%ebx)(%esp), %eax what I'm trying to do is basically create a loop that extras the next argument(fixed size) from the stack. example: int…
rlhh
  • 893
  • 3
  • 17
  • 32
0
votes
1 answer

Strcat in assembly

I'm trying to concatenate two strings in Assembly but I can't seem to get it working. I have the following piece of code: .data message: .asciz "message" leading: .asciz "leading" .globl main main: push $message push $leading call…
Devos50
  • 2,025
  • 4
  • 25
  • 56
-1
votes
1 answer

Confusion about addressing modes - how does a register by itself outside () work as an ADDRESS_OR_OFFSET constant?

In Programming from the Ground Up, in chapter 3 I read The general form of memory address references is this: ADDRESS_OR_OFFSET(%BASE_OR_OFFSET, %INDEX, MULTIPLIER) All fields are optional. To calculate the address, simply perform the following…
Enlico
  • 23,259
  • 6
  • 48
  • 102
-1
votes
2 answers

Extract LSB from integer in assembly x86-64 At&t

I am trying to extract the LSB from an integer in assembly. I know you can bit shift left and right, however I have not found how you can just get the LSB of some integer. Suppose %rdi stores 13 00...00001101 ^ How do I extract the last…
-1
votes
1 answer

Is a .byte array the same as declaring an .asciz string literal?

This may seem like an odd question, but does x64 treat arrays declared as .byte segments the same as .asciz arrays? The context is that I’m reading in a string using the read system call (just to see if I can). I store this in a buffer array of type…
-1
votes
1 answer

Taking user input and incrementing the number by 1

In this code the user is asked to supply a number. Once they do so the number should be incremented by 1. This code works when you hard code the value of the number on line 11 (movq $number , %rsi). If I replace "$Number" with an actual digit like…
-1
votes
1 answer

Update array in assembly

Just starting to learn assembly, so I am having trouble with some basic. For example, I am trying to modify a file that normally runs to find the maximum value. What I am trying to do is iterate through the data_items and modify it by changing the…
Eric
  • 1
  • 2