Basic Instructions

Basic Instructions#

Category

Operation Type

Opcodes and Links

Explanation

Basic Data Movement

Register/Memory Move

mov

Transfers data between registers, memory, or loads immediate values

Conditional Move

cmovcc

Moves data only if condition code (cc) is met (e.g., cmove, cmovg)

Extended Move

movsx, movzx

Sign-extend (movsx) or zero-extend (movzx) smaller values to larger sizes

Stack Operations

Push

push

Decrements RSP and stores operand on stack

Pop

pop

Loads value from stack and increments RSP

Enter/Leave

enter, leave

Create/remove stack frame

Arithmetic

Basic Math

add, sub

Addition and subtraction

Multiplication

mul, imul

Unsigned (mul) and signed (imul) multiplication

Division

div, idiv

Unsigned (div) and signed (idiv) division

Quick Math

inc, dec

Increment or decrement by 1

Complex Math

lea

Load Effective Address

Bitwise

Logic

and, or, xor

Basic boolean operations

Shifts

shl, shr

Logical left/right shift

Arithmetic Shifts

sal, sar

Arithmetic left/right shift

Rotates

rol, ror, rcl, rcr

Rotate bits

Comparison

Compare

cmp

Subtracts operands and sets flags

Test

test

ANDs operands and sets flags

Control Flow

Unconditional Jump

jmp

Direct jump to location

Conditional Jump

jcc

Jump if condition met

Call/Return

call, ret

Subroutine call and return

Flag Control

Carry Flag

clc, stc

Clear/Set carry flag

Direction Flag

cld, std

Clear/Set direction flag

Interrupt Flag

cli, sti

Clear/Set interrupt flag

System

System Call

syscall

Calls operating system function

Interrupt

int

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
Pourquoi cette page est en anglais ?

Memory Operations#

Instruction

Operation

Size

Link

stosb

Store AL

Byte

Store from AL to [RDI]

stosw

Store AX

Word

Store from AX to [RDI]

stosd

Store EAX

DWord

Store from EAX to [RDI]

stosq

Store RAX

QWord

Store from RAX to [RDI]

scasb

Scan Byte

Byte

Compares AL with byte at [RDI]

scasw

Scan Word

Word

Compares AX with word at [RDI]

scasd

Scan Double Word

DWord

Compares EAX with dword at [RDI]

scasq

Scan Quad Word

QWord

Compares RAX with qword at [RDI]

cmpsb

Compare Byte

Byte

Compare [RSI] with [RDI]

cmpsw

Compare Word

Word

Compare [RSI] with [RDI]

cmpsd

Compare Double

DWord

Compare [RSI] with [RDI]

cmpsq

Compare Quad

QWord

Compare [RSI] with [RDI]

movsb

Move Byte

Byte

Move from [RSI] to [RDI]

movsw

Move Word

Word

Move from [RSI] to [RDI]

movsd

Move Double

DWord

Move from [RSI] to [RDI]

movsq

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:

  1. 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]

  2. 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

  3. 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) and STD 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