Assembly Syntax
Required Knowledge
You will need to understand the basic Assembly concepts outlines in
AssemblyDef.
Assembly Syntax
There are several main differences between the Intel and AT&T syntaxes which will be highlighted in the following article.
It is important that you know the basics of assembly to carry on with this article, if you do not understand fundamental concepts like what registers and opcodes are, as well as how memory is addressed, please refer to the aforementioned link in the required knowledge section.
If you know all that stuff, the following may just make sense to you ;)
Using the Intel syntax as a baseline, let us look at a simple instruction. The instruction is to move the value 5 into the register eax.
The Intel syntax looks something like this:
mov eax, 5
As we can see, the syntax for this instruction is straightforward.
mov destination, source
However, the AT&T syntax has a little more subtance to it, the syntax to perform the same instruction as above would be written thusly:
movl $5, %eax
There are several differences here, notably the 5 and eax have swapped positions. This is because in AT&T syntax the mov instruction is written like this:
movl source, destination
Another difference highlighted by these two instructions is that in Intel syntax we simply specify the instruction, mov, but in AT&T syntax we have to specify a specific version of an instruction. In this case, movl corresponds to mov long value. This is to say that because we are moving a value into EAX (which is 32 bits wide, the same as the long datatype), we must use the 'long' version of the mov instruction. ie. Append 'l' onto the word mov.
If we were to move 5 into AX, we would use the movw instruction (mov word) and similarly 5 into AL or AH, we would use the movb (mov byte) instruction.
Here are some examples of operations which require type suffixes.
| Intel instruction (Instruction name) |
Byte version |
Word version |
Long (DWORD) version |
| mov (move) |
movb |
movw |
movl |
| push (push to stack) |
- |
pushw |
pushl |
| and (Binary and) |
andb |
andw |
andl |
Ofcourse there are many more instructions which require these suffixes, you will have to work out which require these yourself (though it should be fairly obvious if you know the operands of the instruction).
Now... let's look back to the original example for the move instruction.
'eax' is a register, thus we must prefix it with a % sign. Similarly, we must prefix the 'immediate data' (the 5 in this case) shuld be prefixed with a $ sign.
<Talk about how memory addressing differs>
Intel syntax examples:
AT&T syntax examples:
Stub BLAH BLAH.
Related links
Categories
CategoryDefinitions
There are no comments on this page. [Add comment]