Say hello to x86_64 Assembly [part 6]

It is sixth part of Say hello to x86_64 Assembly and here we will look on AT&T assembler syntax. Previously we used nasm assembler in all parts, but there are some another assemblers with different syntax, fasm, yasm and others. As i wrote above we will look on gas (GNU assembler) and difference between it's syntax and nasm. GCC uses GNU assembler, so if you see at assembler output for simple hello world:

You will see following output:

Looks different then nasm Hello world, let's look on some differences.

AT&T syntax


I don't know how about you, but when I start to write assembler program, usually I'm starting from sections definition. Let's look on simple example:

You can note two little differences here:
  • Section definition starts with . symbol
  • Main routine defines with .globl instead global as we do it in nasm
Also gas uses another directives for data defintion:

Operands order

When we write assembler program with nasm, we have following general syntax for data manipulation:
mov destination, source
With GNU assembler we have back order i.e.:
mov source, destination
For example:

Also you can not here that registers starts with % symbol. If you're using direct operands, need to use $ symbol:

Size of operands and operation syntax

Sometimes when we need to get part of memory, for example first byte of 64 register, we used following syntax:

There is another way for such operations in gas. We don't define size in operands but in instruction:

GNU assembler has 6 postfixes for operations:
  • b - 1 byte operands
  • w - 2 bytes operands
  • l - 4 bytes operands
  • q - 8 bytes operands
  • t - 10 bytes operands
  • o - 16 bytes operands
This rule is not only mov instruction, but also for all another like addl, xorb, cmpw and etc...

Memory access

You can note that we used ( ) brackets in previous example instead [ ] in nasm example. To dereference values in parentheses are used GAS: (%rax), for example:


GNU assembler supports following operators for far functions call and jumps:
  • lcall $section, $offset
Far jump--A jump to an instruction located in a different segment than the current code segment but at the same privilege level, sometimes referred to as an intersegment jump.


GNU assembler supports 3 types of comments:
  • # - single line comments
  • // - single line comments
  • /* */ - for multiline comments


It was a sixth part of series 'say hello to x64 assembly'. Of course here described not of all differences between Intel and AT&T syntax, but it's good start to not see at AT&T code as on foreign language if you already know nasm. if you will have a questions/suggestions write me a comment or ping me at twitter for discussing. If you're interesting in some additional themes about assembly and x86_64 programming write me a comment and I will try to write blog post about it in near time.

All another parts you can find - here.

All source code you can find as every time - here.

English is not my first language, so you'll find mistakes in blog post please write me in comments or drop me email .

No comments: