You will see following output:
Looks different then nasm Hello world, let's look on some differences.
SectionsI 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
Operands orderWhen we write assembler program with nasm, we have following general syntax for data manipulation:
mov destination, sourceWith GNU assembler we have back order i.e.:
mov source, destinationFor 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 syntaxSometimes 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
Memory accessYou can note that we used ( ) brackets in previous example instead [ ] in nasm example. To dereference values in parentheses are used GAS: (%rax), for example:
JumpsGNU 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.
CommentsGNU 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 .