Assembly Language Instructions Cheat Sheet

Introduction

Assembly language is a low-level programming language that has a strong correspondence between the language’s instructions and the processor’s machine code instructions. This cheat sheet focuses primarily on x86 assembly with notes on other architectures where relevant.

Common Terminology

  • Register: CPU’s internal storage locations
  • Instruction: A single operation the CPU can perform
  • Operand: Data that an instruction operates on
  • Addressing Mode: How memory locations are specified
  • Mnemonic: Human-readable instruction name

Register Sets

x86 (32-bit) Registers

General Purpose Registers

  • EAX: Accumulator (arithmetic operations, function return values)
  • EBX: Base (pointer to data in memory)
  • ECX: Counter (loop counter)
  • EDX: Data (arithmetic operations)
  • ESI: Source Index (string operations source)
  • EDI: Destination Index (string operations destination)
  • ESP: Stack Pointer (points to top of stack)
  • EBP: Base Pointer (points to base of stack frame)

Segment Registers

  • CS: Code Segment
  • DS: Data Segment
  • SS: Stack Segment
  • ES, FS, GS: Extra Segments

Status Flags (EFLAGS)

  • CF: Carry Flag
  • ZF: Zero Flag
  • SF: Sign Flag
  • OF: Overflow Flag
  • PF: Parity Flag
  • AF: Auxiliary Carry Flag

x86-64 (64-bit) Additional Registers

  • RAX, RBX, RCX, RDX, RSI, RDI, RSP, RBP: 64-bit extensions of 32-bit registers
  • R8-R15: Additional 64-bit registers
  • XMM0-XMM15: 128-bit SIMD registers

ARM Registers

  • R0-R12: General purpose registers
  • R13 (SP): Stack pointer
  • R14 (LR): Link register (return address)
  • R15 (PC): Program counter

MIPS Registers

  • $0: Constant zero
  • $1: Reserved for assembler
  • $2-$3: Function results
  • $4-$7: Function arguments
  • $8-$15, $24-$25: Temporaries
  • $16-$23: Saved registers
  • $26-$27: Reserved for OS
  • $28 (GP): Global pointer
  • $29 (SP): Stack pointer
  • $30 (FP): Frame pointer
  • $31 (RA): Return address

Data Movement Instructions

x86/x64

InstructionDescriptionExample
MOVMove data between registers or between register and memoryMOV EAX, EBX
PUSHPush value onto stackPUSH EAX
POPPop value from stackPOP EAX
XCHGExchange valuesXCHG EAX, EBX
LEALoad effective addressLEA EAX, [EBX+4*ECX+8]
MOVZXMove with zero extendMOVZX EAX, BL
MOVSXMove with sign extendMOVSX EAX, BL

ARM

InstructionDescriptionExample
MOVMove dataMOV R0, R1
LDRLoad from memoryLDR R0, [R1]
STRStore to memorySTR R0, [R1]
PUSHPush to stackPUSH {R0-R3, LR}
POPPop from stackPOP {R0-R3, PC}

MIPS

InstructionDescriptionExample
LWLoad wordLW $t0, 4($sp)
SWStore wordSW $t0, 4($sp)
MOVEMove between registersMOVE $t0, $t1
LILoad immediateLI $t0, 42

Arithmetic Instructions

x86/x64

InstructionDescriptionExample
ADDAddADD EAX, EBX
SUBSubtractSUB EAX, EBX
MULUnsigned multiplyMUL EBX (EAX *= EBX)
IMULSigned multiplyIMUL EAX, EBX, 4 (EAX = EBX * 4)
DIVUnsigned divideDIV EBX (EDX:EAX / EBX)
IDIVSigned divideIDIV EBX (EDX:EAX / EBX)
INCIncrementINC EAX
DECDecrementDEC EAX
NEGNegateNEG EAX
CMPCompareCMP EAX, EBX

ARM

InstructionDescriptionExample
ADDAddADD R0, R1, R2 (R0 = R1 + R2)
SUBSubtractSUB R0, R1, R2 (R0 = R1 – R2)
MULMultiplyMUL R0, R1, R2 (R0 = R1 * R2)
SDIVSigned divideSDIV R0, R1, R2 (R0 = R1 / R2)
CMPCompareCMP R0, R1

MIPS

InstructionDescriptionExample
ADDAddADD $t0, $t1, $t2
ADDIAdd immediateADDI $t0, $t1, 42
SUBSubtractSUB $t0, $t1, $t2
MULTMultiplyMULT $t1, $t2 (result in HI:LO)
DIVDivideDIV $t1, $t2 (result in HI:LO)

Logical Instructions

x86/x64

InstructionDescriptionExample
ANDBitwise ANDAND EAX, EBX
ORBitwise OROR EAX, EBX
XORBitwise XORXOR EAX, EBX
NOTBitwise NOTNOT EAX
SHLShift leftSHL EAX, 2
SHRShift rightSHR EAX, 2
SARShift arithmetic rightSAR EAX, 2
ROLRotate leftROL EAX, 1
RORRotate rightROR EAX, 1
TESTTest bits (AND without storing)TEST EAX, 1

ARM

InstructionDescriptionExample
ANDBitwise ANDAND R0, R1, R2
ORRBitwise ORORR R0, R1, R2
EORBitwise XOREOR R0, R1, R2
MVNBitwise NOTMVN R0, R1
LSLLogical shift leftLSL R0, R1, #2
LSRLogical shift rightLSR R0, R1, #2
ASRArithmetic shift rightASR R0, R1, #2

MIPS

InstructionDescriptionExample
ANDBitwise ANDAND $t0, $t1, $t2
ANDIBitwise AND immediateANDI $t0, $t1, 42
ORBitwise OROR $t0, $t1, $t2
XORBitwise XORXOR $t0, $t1, $t2
SLLShift left logicalSLL $t0, $t1, 2
SRLShift right logicalSRL $t0, $t1, 2
SRAShift right arithmeticSRA $t0, $t1, 2

Control Flow Instructions

x86/x64

Unconditional Jumps

InstructionDescriptionExample
JMPJump to addressJMP label
CALLCall procedureCALL procedure
RETReturn from procedureRET

Conditional Jumps

InstructionDescriptionCondition
JE/JZJump if equal / zeroZF = 1
JNE/JNZJump if not equal / not zeroZF = 0
JG/JNLEJump if greater (signed)ZF = 0 and SF = OF
JGE/JNLJump if greater or equal (signed)SF = OF
JL/JNGEJump if less (signed)SF ≠ OF
JLE/JNGJump if less or equal (signed)ZF = 1 or SF ≠ OF
JA/JNBEJump if above (unsigned)CF = 0 and ZF = 0
JAE/JNBJump if above or equal (unsigned)CF = 0
JB/JNAEJump if below (unsigned)CF = 1
JBE/JNAJump if below or equal (unsigned)CF = 1 or ZF = 1
JCJump if carryCF = 1
JNCJump if not carryCF = 0
JOJump if overflowOF = 1
JNOJump if not overflowOF = 0
JSJump if sign (negative)SF = 1
JNSJump if not sign (positive)SF = 0

ARM

InstructionDescriptionExample
BBranchB label
BLBranch with link (call)BL function
BXBranch and exchangeBX LR (return)
BEQBranch if equalBEQ label
BNEBranch if not equalBNE label
BLTBranch if less thanBLT label
BGTBranch if greater thanBGT label
BLEBranch if less or equalBLE label
BGEBranch if greater or equalBGE label

MIPS

InstructionDescriptionExample
JJumpJ label
JALJump and link (call)JAL function
JRJump register (return)JR $ra
BEQBranch if equalBEQ $t0, $t1, label
BNEBranch if not equalBNE $t0, $t1, label
BGTZBranch if greater than zeroBGTZ $t0, label
BLTZBranch if less than zeroBLTZ $t0, label
BGEZBranch if greater or equal to zeroBGEZ $t0, label
BLEZBranch if less or equal to zeroBLEZ $t0, label

Memory Addressing Modes

x86/x64

Addressing ModeSyntax ExampleDescription
RegisterMOV EAX, EBXOperand is in register
ImmediateMOV EAX, 42Constant value
DirectMOV EAX, [0x1000]Value at memory address
Register IndirectMOV EAX, [EBX]Value at address in register
Base + DisplacementMOV EAX, [EBX+8]Value at register + offset
Base + IndexMOV EAX, [EBX+ECX]Value at register + register
Base + Index + DisplacementMOV EAX, [EBX+ECX+8]Value at register + register + offset
Scaled IndexMOV EAX, [EBX+4*ECX]Value at register + (register * scale)
Scaled Index + DisplacementMOV EAX, [EBX+4*ECX+8]Value at register + (register * scale) + offset

ARM

Addressing ModeSyntax ExampleDescription
RegisterMOV R0, R1Operand is in register
ImmediateMOV R0, #42Constant value
Register IndirectLDR R0, [R1]Value at address in register
Pre-indexedLDR R0, [R1, #4]!Value at address in register + offset, base updated
Post-indexedLDR R0, [R1], #4Value at address in register, base updated after
PC RelativeLDR R0, [PC, #12]Value at PC + offset

MIPS

Addressing ModeSyntax ExampleDescription
RegisterADD $t0, $t1, $t2Operand is in register
ImmediateADDI $t0, $t1, 42Constant value
Base + DisplacementLW $t0, 4($t1)Value at register + offset

SIMD Instructions (x86/x64)

SSE/AVX Registers

  • XMM0-XMM15: 128-bit registers
  • YMM0-YMM15: 256-bit registers (AVX)
  • ZMM0-ZMM31: 512-bit registers (AVX-512)

Common SSE Instructions

InstructionDescriptionExample
MOVAPSMove aligned packed single precisionMOVAPS XMM0, XMM1
MOVUPSMove unaligned packed single precisionMOVUPS XMM0, [EAX]
ADDPSAdd packed single precisionADDPS XMM0, XMM1
SUBPSSubtract packed single precisionSUBPS XMM0, XMM1
MULPSMultiply packed single precisionMULPS XMM0, XMM1
DIVPSDivide packed single precisionDIVPS XMM0, XMM1
SQRTPSSquare root of packed single precisionSQRTPS XMM0, XMM1
MAXPSMaximum of packed single precisionMAXPS XMM0, XMM1
MINPSMinimum of packed single precisionMINPS XMM0, XMM1

Common AVX Instructions

InstructionDescriptionExample
VMOVAPSMove aligned packed single precisionVMOVAPS YMM0, YMM1
VADDPSAdd packed single precisionVADDPS YMM0, YMM1, YMM2
VSUBPSSubtract packed single precisionVSUBPS YMM0, YMM1, YMM2
VMULPSMultiply packed single precisionVMULPS YMM0, YMM1, YMM2
VDIVPSDivide packed single precisionVDIVPS YMM0, YMM1, YMM2

System Instructions

x86/x64

InstructionDescriptionExample
INTCall to interruptINT 0x80 (Linux syscall, legacy)
SYSCALLSystem call (64-bit)SYSCALL
SYSENTERFast system callSYSENTER
INInput from portIN AL, 0x60
OUTOutput to portOUT 0x60, AL
CLIClear interrupt flagCLI
STISet interrupt flagSTI
HLTHalt processorHLT
CPUIDCPU identificationCPUID

String Operations (x86/x64)

InstructionDescription
MOVSMove string
CMPSCompare string
SCASScan string
LODSLoad string
STOSStore string
REPRepeat prefix (repeat until ECX = 0)
REPE/REPZRepeat while equal/zero
REPNE/REPNZRepeat while not equal/not zero

Common x86/x64 Calling Conventions

cdecl (C Declaration)

  • Arguments pushed on stack from right to left
  • Caller cleans the stack
  • EAX, ECX, EDX are caller-saved
  • Other registers are callee-saved
  • Return value in EAX

stdcall (Standard Call)

  • Arguments pushed on stack from right to left
  • Callee cleans the stack
  • Return value in EAX

fastcall

  • First two arguments in ECX and EDX
  • Remaining arguments pushed on stack from right to left
  • Callee cleans the stack
  • Return value in EAX

x64 (Microsoft)

  • First four arguments in RCX, RDX, R8, R9
  • Additional arguments pushed on stack from right to left
  • 32 bytes of shadow space on stack
  • Return value in RAX

x64 (System V – Linux, macOS)

  • First six integer/pointer arguments in RDI, RSI, RDX, RCX, R8, R9
  • First eight floating-point arguments in XMM0-XMM7
  • Additional arguments pushed on stack from right to left
  • Return value in RAX (integer) or XMM0 (floating-point)

Common Assembler Directives

General Directives

DirectiveDescription
.dataStart data section
.textStart code section
.global / .globlMake symbol global
.externDeclare external symbol
.equ / .setDefine constant
.includeInclude file
.macroDefine macro
.endmEnd macro definition
.ifConditional assembly
.endifEnd conditional assembly

Data Definition Directives

DirectiveDescription
.byteDefine byte
.wordDefine word (2 bytes)
.long / .intDefine long (4 bytes)
.quadDefine quadword (8 bytes)
.floatDefine single precision float
.doubleDefine double precision float
.asciiDefine ASCII string (no null terminator)
.asciz / .stringDefine ASCII string with null terminator
.space / .skipReserve space
.alignAlign to boundary

Common Assembly Tasks (x86/x64)

Function Prologue (x86)

function:
    push ebp            ; Save old base pointer
    mov ebp, esp        ; Set new base pointer
    sub esp, X          ; Allocate X bytes of local variables
    push ebx            ; Save callee-saved registers
    push esi
    push edi
    ; Function body

Function Epilogue (x86)

    pop edi             ; Restore callee-saved registers
    pop esi
    pop ebx
    mov esp, ebp        ; Deallocate local variables
    pop ebp             ; Restore old base pointer
    ret                 ; Return to caller

Function Prologue (x64, Microsoft)

function:
    push rbp            ; Save old base pointer
    mov rbp, rsp        ; Set new base pointer
    sub rsp, X          ; Allocate X bytes of local variables (X must be multiple of 16)
    ; Save non-volatile registers if used
    ; Function body

Function Epilogue (x64, Microsoft)

    ; Restore non-volatile registers if saved
    mov rsp, rbp        ; Deallocate local variables
    pop rbp             ; Restore old base pointer
    ret                 ; Return to caller

Memory Access Examples (x86)

; Accessing function parameters (cdecl)
mov eax, [ebp+8]    ; First parameter
mov ecx, [ebp+12]   ; Second parameter

; Accessing local variables
mov [ebp-4], eax    ; First local variable
mov [ebp-8], ecx    ; Second local variable

; Array indexing (array of 4-byte elements)
mov eax, [ebx+ecx*4]    ; array[ecx]

Memory Access Examples (x64, Microsoft)

; Parameters already in registers: RCX, RDX, R8, R9
; Accessing parameters beyond the first four
mov rax, [rbp+16]   ; Fifth parameter

; Accessing local variables
mov [rbp-8], rax    ; First local variable
mov [rbp-16], rcx   ; Second local variable

C-Style Array Access (x86)

; Accessing array[i] where each element is 4 bytes
; Assume:
;   - EBX points to the array (array base address)
;   - ECX contains i (the index)

; Method 1: Use scaled indexed addressing
mov eax, [ebx+ecx*4]    ; Load array[i] into EAX

; Method 2: Calculate address manually
mov eax, ecx            ; Copy i to EAX
shl eax, 2              ; Multiply by 4 (size of each element)
add eax, ebx            ; Add to base address
mov eax, [eax]          ; Load array[i] into EAX

Loop Structure (x86)

    mov ecx, 10         ; Initialize counter
loop_start:
    ; Loop body
    
    dec ecx             ; Decrement counter
    jnz loop_start      ; Jump if not zero

Loop Structure with array (x86)

    mov ecx, 10         ; Array length
    mov eax, 0          ; Sum
    mov esi, array      ; Array pointer
loop_start:
    add eax, [esi]      ; Add current element to sum
    add esi, 4          ; Move to next element
    dec ecx             ; Decrement counter
    jnz loop_start      ; Jump if not zero

Floating-Point Operations (x87 FPU)

InstructionDescriptionExample
FLDLoad floating-point valueFLD DWORD PTR [EAX]
FSTStore floating-point valueFST DWORD PTR [EAX]
FSTPStore floating-point value and popFSTP DWORD PTR [EAX]
FADDAdd floating-pointFADD ST, ST(1)
FSUBSubtract floating-pointFSUB ST, ST(1)
FMULMultiply floating-pointFMUL ST, ST(1)
FDIVDivide floating-pointFDIV ST, ST(1)
FCOMCompare floating-pointFCOM ST(1)
FSINSineFSIN
FCOSCosineFCOS
FSQRTSquare rootFSQRT

Tips and Best Practices

  1. Comment your code: Assembly is difficult to read and understand
  2. Use meaningful labels: Makes the code more readable
  3. Be consistent with naming conventions: Helps with maintenance
  4. Save/restore registers: Especially in functions and interrupts
  5. Align your data: For performance and to avoid bus errors
  6. Use macros for repetitive tasks: Reduces code duplication
  7. Avoid self-modifying code: Hard to maintain and may not work on modern systems
  8. Use higher-level constructs when available: Many assemblers support structured programming
  9. Be careful with overflow and boundary conditions: Assembly provides minimal protection
  10. Test thoroughly: Assembly errors can be subtle and difficult to find

Resources and References

  • Intel® 64 and IA-32 Architectures Software Developer Manuals
  • ARM Architecture Reference Manual
  • MIPS Architecture Reference Manual
  • AMD64 Architecture Programmer’s Manual
  • “Assembly Language for x86 Processors” by Kip Irvine
  • “Programming from the Ground Up” by Jonathan Bartlett
  • “Art of Assembly Language” by Randall Hyde
Scroll to Top