Programming/Assembly
Jump to navigation
Jump to search
Syntax Types
For 32 bit (x86) assembly, there are two main syntax types. AT&T is mostly used in Unix environments, while Intel is mostly used in MS-DOS and Windows.
The differences are as follows:
AT&T | Intel | |
---|---|---|
Signs | Instructions need size definition suffix (see #Instruction Sizes). Values need % prefix for registers, and $ prefix for constants. Ex: %eax
|
Automatically detects size and type of value. Signs are not needed. Ex: eax
|
Value Order | Source first, destination second. Ex: mov $5, %eax
|
Destination first, source second. Ex: mov eax, 5
|
Value Size | Size suffix (see #Instruction Sizes) must be added to instruction. Ex: addl %eax, %ebx
|
Size automatically derived from register used. In instances where size is ambiguous, must use a size keyword (byte, word, dword, qword). Ex: add eax, ebx
|
Effective Address | Uses general memory address syntax. Ex: (%ebx, %ecx, 4)
|
Uses arithmetic expressions in square brackets. Ex: [ebx + ecx*4]
|
Registers
The following registers exist in 64 and 32 bit assembly.
Stack Pointer | Stack Base Pointer | Accumulator | Base | Counter | Data | Source | Destination | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
64 Bit | RSP | RBP | RAX | RBX | RCX | RDX | RSI | RDI | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
32 Bit | ESP | EBP | EAX | EBX | ECX | EDX | ESI | EDI | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
16 Bit | SP | BP | AX | BX | CX | DX | SI | DI | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
8 Bit | SPL | BPL | AH | AL | BH | BL | CH | CL | DH | DL | SIL | DIL | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The following registers only exist in 64 bit assembly.
Temp 1 | Temp 2 | Temp 3 | Temp 4 | Temp 5 | Temp 6 | Temp 7 | Temp 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
64 Bit | R8 | R9 | R10 | R11 | R12 | R13 | R14 | R15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
32 Bit | R8D | R9D | R10D | R11D | R12D | R13D | R14D | R15D | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
16 Bit | R8W | R9W | R10W | R11W | R12W | R13W | R14W | R15W | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
8 Bit | R8B | R9B | R10B | R11B | R12B | R13B | R14B | R15B | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
In-depth details of how assembly register and function calling should work: https://www.cs.princeton.edu/courses/archive/spring11/cos217/lectures/15AssemblyFunctions.pdf
Instruction Sizes
In 64 bit assembly, some assembly instructions will have letters appended to the end of the instruction, indicating the size of data being referenced. The letters are the following:
- Byte (b) - A one-byte (8 bit) value.
- Word (w) - A two-byte (16 bit) value.
- DoubleWord (l) - A four-byte (32 bit) value.
- QuadWord (q) - A eight-byte (64 bit) value.
Instructions
- mov <a>, - Copies data location from one to the other.