Basic Instructions#
Category |
Operation Type |
Opcodes and Links |
Explanation |
---|---|---|---|
Basic Data Movement |
Register/Memory Move |
Transfers data between registers, memory, or loads immediate values |
|
Conditional Move |
Moves data only if condition code (cc) is met (e.g., |
||
Extended Move |
Sign-extend ( |
||
Stack Operations |
Push |
Decrements RSP and stores operand on stack |
|
Pop |
Loads value from stack and increments RSP |
||
Enter/Leave |
Create/remove stack frame |
||
Arithmetic |
Basic Math |
Addition and subtraction |
|
Multiplication |
Unsigned ( |
||
Division |
Unsigned ( |
||
Quick Math |
Increment or decrement by 1 |
||
Complex Math |
Load Effective Address |
||
Bitwise |
Logic |
Basic boolean operations |
|
Shifts |
Logical left/right shift |
||
Arithmetic Shifts |
Arithmetic left/right shift |
||
Rotates |
Rotate bits |
||
Comparison |
Compare |
Subtracts operands and sets flags |
|
Test |
ANDs operands and sets flags |
||
Control Flow |
Unconditional Jump |
Direct jump to location |
|
Conditional Jump |
Jump if condition met |
||
Call/Return |
Subroutine call and return |
||
Flag Control |
Carry Flag |
Clear/Set carry flag |
|
Direction Flag |
Clear/Set direction flag |
||
Interrupt Flag |
Clear/Set interrupt flag |
||
System |
System Call |
Calls operating system function |
|
Interrupt |
Software interrupt |
lea example:
; Basic array indexing: getting address of array[index]
leal (%ebx, %ecx, 4), %eax # eax = ebx + ecx*4 (array of dwords)
leaq (%rbx, %rcx, 8), %rax # rax = rbx + rcx*8 (array of qwords)
; Addition of multiple values
leal 5(%rax, %rbx), %eax # eax = rax + rbx + 5 (three-operand add)
; Multiplication and addition combined
leal 5(%rax, %rax, 2), %eax # eax = rax * 3 + 5

Memory Operations#
Instruction |
Operation |
Size |
Link |
---|---|---|---|
Store AL |
Byte |
Store from AL to [RDI] |
|
Store AX |
Word |
Store from AX to [RDI] |
|
Store EAX |
DWord |
Store from EAX to [RDI] |
|
Store RAX |
QWord |
Store from RAX to [RDI] |
|
Scan Byte |
Byte |
Compares AL with byte at [RDI] |
|
Scan Word |
Word |
Compares AX with word at [RDI] |
|
Scan Double Word |
DWord |
Compares EAX with dword at [RDI] |
|
Scan Quad Word |
QWord |
Compares RAX with qword at [RDI] |
|
Compare Byte |
Byte |
Compare [RSI] with [RDI] |
|
Compare Word |
Word |
Compare [RSI] with [RDI] |
|
Compare Double |
DWord |
Compare [RSI] with [RDI] |
|
Compare Quad |
QWord |
Compare [RSI] with [RDI] |
|
Move Byte |
Byte |
Move from [RSI] to [RDI] |
|
Move Word |
Word |
Move from [RSI] to [RDI] |
|
Move Double |
DWord |
Move from [RSI] to [RDI] |
|
Move Quad |
QWord |
Move from [RSI] to [RDI] |
REP Instruction Prefixes (Special Explanation):
The REP prefixes are powerful tools that automatically repeat memory operations using RCX as a counter:
rep
(Repeat):Repeats instruction RCX times
Decrements RCX after each operation
Stops when RCX = 0
Best used with MOVS and STOS instructions
Example:
REP MOVSB
copies RCX bytes from [RSI] to [RDI]
repe/repz
(Repeat while Equal/Zero):Repeats instruction while ZF=1 AND RCX>0
Best used with CMPS and SCAS for finding differences
Stops if ZF=0 or RCX=0
Example:
REPE CMPSB
compares strings until mismatch or RCX=0
repne/repnz
(Repeat while Not Equal/Not Zero):Repeats instruction while ZF=0 AND RCX>0
Best used with CMPS and SCAS for finding matches
Stops if ZF=1 or RCX=0
Example:
REPNE SCASB
scans for matching byte in string
Important Notes:
Direction Flag (DF) controls increment/decrement:
When DF=0: RDI/RSI increment after operation
When DF=1: RDI/RSI decrement after operation
Use
CLD
to clear DF (for increment) andSTD
to set DF (for decrement)RCX should be set to the desired count before using REP prefixes
Memory operations always use RDI for destination, cannot be changed to other registers