Appearance
Processor Architecture and Design — Cheat Sheet
Machine model: MiniCPU
- 32-bit, load-store RISC, 16 registers R0–R15 (R0 = constant 0), little-endian.
- Instructions: LDR, STR, ADD, SUB, MUL, BEQ, JMP, MOV, HLT.
- Flags: Z, C, N, V. PC increments by 4.
Instruction cycle (single-cycle view)
text
PC → MAR; read MEM[PC] → IR; PC ← PC+4
Decode opcode, read register file
ALU computes result
(optionally) write MEM or write register filePipeline stages
IF Fetch instruction (IR ← MEM[PC])
ID Decode + read registers
EX ALU operation
MEM Access data memory
WB Write result to registertext
Ideal CPI = 1 instruction/cycle (full pipeline)
Non-pipelined CPI ≈ #stages per instructionHazards
text
Structural = hardware resource conflict → add resource or stall
Data = operand not ready → forwarding or stall
Control = branch target unknown → predict or delay branchtext
Load-use stall (no forwarding for load→use):
LW R1,... ; ADD R2,R1,R3 → 1 stall cycleBranch prediction
- Static: always not-taken, or backward=taen.
- 2-bit saturating counter: strongly/weakly taken/not-taken.
- Misprediction cost = flush pipeline (≈ #stages cycles lost).
AMAT
text
Average Memory Access Time = Hit Time + Miss Rate × Miss Penalty
TLB-miss AMAT = t_hit + (1 - TLB_hit_rate) × t_page_walkCache
text
Cache params: size, block size, associativity
Miss types: compulsory, capacity, conflict
Write policies: write-through vs write-back; write-allocate vs no-write-allocate
Set index = (block_number mod number_of_sets); tag = block_number / sets
MESI: Modified, Exclusive, Shared, InvalidMemory hierarchy (per-byte cost, latency)
Registers < L1 < L2 (< L3) < RAM < SSD < HDD < tape/networkAddressing & translation
text
Virtual address: [ VPN ][ offset ]
Physical addr: [ PFN ][ offset ]
Translation: page table (per process), base register → PT in memory
MMU does it per access; TLB caches recent VPN→PFN
Protection bits per PTE: P, R/W, X, U/S, dirty, accessedRISC vs CISC
text
RISC: load-store, fixed/simple, ~1 CPI, easy pipelining, more instructions
CISC: memory-to-memory, variable, complex, microcode, fewer instructions| ISA | Type | Notes |
|---|---|---|
| x86 / x86-64 | CISC | Desktop/server |
| ARM/AArch64 | RISC | Mobile → server |
| RISC-V | RISC | Open/standard |
| MIPS | RISC | Teaching |
Exceptions, interrupts, traps
text
Exception (synchronous) → fault/recoverable, or abort/fatal
Interrupt (asynchronous) → maskable IRQ / non-maskable NMI
Trap (syscall) → deliberate, into kernel
Flow: finish instr → save PC/flags → kernel mode → vector → ISR → restoreProtection rings
text
x86: ring 0 (kernel) → ring 3 (user). Only ring 0 executes privileged I/O.
ARM: EL1 (kernel) / EL0 (user).System call (x86-64)
text
mov rax, <number> ; syscall number
mov rdi, <arg1> ; args in rdi, rsi, rdx, r10, r8, r9
syscall ; enter kernel; result in rax; ret with sysretBoot
text
BIOS/UEFI → bootloader (GRUB/systemd-boot) → kernel + initrd → /sbin/init (PID 1) → systemd targetsVirtual memory notes
text
Page size typical: 4 KiB. Page table per process.
Demand paging: load on first touch.
Copy-on-write: share after fork, copy on write.
Replacement: LRU approximated via accessed/dirty bits.