Computer Architecture Cheatsheet

Instruction Set Architecture

Use this Computer Architecture reference while you build software engineering projects, review code, or refresh the syntax you reach for most.

What an ISA Defines

An ISA is the hardware-software interface contract. It specifies:

  • Instruction encodings (binary formats)
  • Programmer-visible register set
  • Data types and sizes supported
  • Memory model (addressing, alignment)
  • Privilege levels and protection
  • Exception and interrupt behavior
  • Calling conventions (by convention, not always ISA-mandated)

RISC vs CISC

PropertyRISCCISC
InstructionsFixed-size, simpleVariable-size, complex
Memory accessLoad/store onlyOperands can be in memory
RegistersMany (≥32)Fewer (x86 historically 8)
Cycles per instructionUsually 1 (ideally)1 to many
Compiler complexityHigherLower
ExamplesARM, RISC-V, MIPSx86, x86-64, VAX

Modern x86 CPUs internally translate CISC instructions into RISC-like micro-ops (µops), blurring the distinction.

Instruction Types

ClassExamplesDescription
Data transferMOV, LDR, SWRegister ↔ register, register ↔ memory
ArithmeticADD, SUB, MUL, DIVInteger/FP computation
LogicalAND, OR, XOR, NOTBitwise operations
Shift/rotateSHL, SHR, ROLBit displacement
Control flowJMP, BEQ, CALL, RETChange PC
ComparisonCMP, TESTSet condition flags
SystemSYSCALL, INT, HLTOS interface, halt
SIMDVADD, VMULPSParallel vector ops

Instruction Formats

RISC-V (32-bit fixed-width, 6 formats)

R-type (register):  [funct7|rs2|rs1|funct3|rd|opcode]
                      7     5   5    3     5    7  bits

I-type (immediate): [  imm[11:0] |rs1|funct3|rd|opcode]
                         12       5    3     5    7

S-type (store):     [imm[11:5]|rs2|rs1|funct3|imm[4:0]|opcode]

B-type (branch):    [imm[12|10:5]|rs2|rs1|funct3|imm[4:1|11]|opcode]

U-type (upper imm): [     imm[31:12]      |rd|opcode]

J-type (jump):      [imm[20|10:1|11|19:12]|rd|opcode]

x86-64 (variable-width, 1–15 bytes)

[Prefixes 04 bytes][REX 01][Opcode 13][ModRM 01][SIB 01][Disp 04][Imm 04]
  • ModRM byte encodes addressing mode, source, destination
  • REX prefix extends registers from 8 to 16 (r8–r15)

Addressing Modes

ModeSyntaxEffective address / value
Immediate#5 / MOV r0, #5Constant 5 (no memory access)
Registerr1Value in r1
Direct / Absolute[0x1000]Memory[0x1000]
Register indirect[r1]Memory[r1]
Base + offset[r1 + 8]Memory[r1 + 8]
Indexed[r1 + r2]Memory[r1 + r2]
Scaled indexed[r1 + r2*4 + 8]Memory[r1 + r2×4 + 8]
PC-relativePC + offsetPosition-independent code
Auto-increment[r1++]Memory[r1]; r1 ← r1 + 1

Register Files

x86-64 General-Purpose Registers

64-bit32-bit16-bit8-bit high8-bit lowConventional role
raxeaxaxahalReturn value, accumulator
rbxebxbxbhblCallee-saved
rcxecxcxchclCounter, 4th arg
rdxedxdxdhdlData, 3rd arg
rsiesisisilSource, 2nd arg
rdiedididilDest, 1st arg
rspespspsplStack pointer
rbpebpbpbplFrame pointer
r8r15r8dr15dr8wr15wr8br15bExtra args / scratch

RISC-V Integer Registers (ABI names)

RegABIRoleSaved by
x0zeroAlways 0
x1raReturn addressCaller
x2spStack pointerCallee
x5–x7t0–t2TemporariesCaller
x8–x9s0–s1Saved registersCallee
x10–x11a0–a1Args / return valsCaller
x12–x17a2–a7ArgumentsCaller
x18–x27s2–s11Saved registersCallee
x28–x31t3–t6TemporariesCaller

Condition Codes / Flags

x86 RFLAGS relevant bits:

FlagMeaningSet when
CFCarryUnsigned overflow / borrow
ZFZeroResult = 0
SFSignResult MSB = 1 (negative)
OFOverflowSigned overflow
PFParityLow byte has even number of 1s
AFAuxiliary carryCarry out of bit 3 (BCD)

Conditional jumps (x86) — selected:

InstructionConditionFlags
JE / JZEqual / zeroZF = 1
JNE / JNZNot equalZF = 0
JL / JNGESigned lessSF ≠ OF
JG / JNLESigned greaterZF = 0 and SF = OF
JB / JNAEUnsigned belowCF = 1
JA / JNBEUnsigned aboveCF = 0 and ZF = 0
JSSign (negative)SF = 1
JOOverflowOF = 1

Calling Conventions

System V AMD64 ABI (Linux / macOS x86-64)

RoleRegisters
Integer arguments (1–6)rdi, rsi, rdx, rcx, r8, r9
FP arguments (1–8)xmm0–xmm7
Return value (integer)rax (rdx for 128-bit)
Return value (FP)xmm0
Caller-savedrax, rcx, rdx, rsi, rdi, r8–r11, xmm0–xmm15
Callee-savedrbx, rbp, r12–r15
Stack alignment16-byte aligned at call

Stack Frame Layout (x86-64)

Higher addresses
+------------------+
| caller's frame   |
+------------------+
| return address   |  ← pushed by CALL
+------------------+
| saved rbp        |  ← PUSH rbp; MOV rbp, rsp
+------------------+
| local variables  |
+------------------+
| outgoing args    |  (if > 6 integer args)
+------------------+  ← rsp (16-byte aligned)
Lower addresses

Privilege Levels

Levelx86 termAccess
0 (most privileged)Ring 0OS kernel; all instructions & I/O
1–2Ring 1–2Rarely used; drivers on some OSes
3 (least privileged)Ring 3User programs; no I/O, no privileged instructions

Privileged instructions (in/out, hlt, lidt, etc.) trap to the OS if executed in Ring 3.

Memory Models

ModelDescriptionExample
Sequential consistencyAll cores see memory ops in program orderSimplest; expensive
Total Store Order (TSO)Stores may be buffered; loads bypass store bufferx86
Relaxed (ARM, POWER)Loads and stores may be reordered; fences requiredARM, RISC-V (weak)

Memory fences / barriers (MFENCE, DMB, FENCE) prevent reordering across the barrier.