new blog 2.0


[0x01]. Notes on Assembly - AT&T vs Intel syntax

There are two main syntaxes for Assembly Language: AT&T and Intel. The former was invented by AT&T Labs in 1960's and is used on all UNIX-based systems, the original intention was to preserve portability and compatibility between different UNIX flavors. The latter was invented by Intel and is commonly used in MS systems. I have a bit of a chicken'n'egg problem here, as I have no idea who ripped off the most part from the other party but it's not relevant nor important here... The main differences between the syntax are as follows:

Mnemonics are case-insensitiveMnemonics are lowercase
case insensitive registers in form of AH, ax, Eax
lowercase registers are preceded with % (percent) sign, as in %eax, %ax
Memory operands are prefixed with size accordingly:
  • byte ptr ADDR - 8 bits
  • word ptr ADDR - 16 bits
  • dword ptr ADDR - 32 bits
  • qword ptr ADDR - 64 bits

machine instructions end with one of three possible suffixes:
  • b - for byte
  • w - for word
  • l - for long word
  • q - for quadruple

e.g. movl, movw, movb
The programmer first specifies the destination and then the source operand.
"mov bx, ax" moves ax to bx
You first specify the source and then the destination operand.
"movw %ax, %bx" will move %ax to %bx.
Immediate operands, like numbers or memory addresses, are entered with "h", "b", or no suffix at all for hex, binary or decimal digits respectivelyImmediate operands are preceded by $ (dollar sign).
Comment is denoted by a ; (colon)A comment is denoted by a # (hash)
Jump and call operands are undelimitedJumps and calls are prefixed by an * (asterisk) that the same C program (main.c), that only returns 0 to the environment would look like this:


.globl _main
pushl %ebp
movl %esp, %ebp
subl $8, %esp
movl $0, %eax

int main(void){
return 0;

[SECTION .text]
push ebp
mov ebp, esp
sub esp, 8
mov eax, 0


No comments: