Section 3 · Revision
Computer Organization and Architecture formula sheet
Addressing modes, ALU and control formulas, cache and AMAT equations, I/O overhead and pipeline timing on one page for last-minute revision.
Instruction set and addressing modes
| Mode | Effective address / operand | Data memory accesses for operand | Typical use |
|---|---|---|---|
| Immediate | operand | 0 | constants |
| Register | operand | 0 | temporaries |
| Direct (absolute) | 1 | globals | |
| Memory indirect | 2 | pointers in memory | |
| Register indirect | 1 | *p |
|
| Base + displacement | 1 | locals (frame pointer), struct fields | |
| Indexed | (times scale) | 1 | arrays |
| PC-relative | 1 | branches, position-independent code | |
| Auto-increment | , then | 1 | step through array, pop |
| Auto-decrement | , then | 1 | push |
-
Field width for choices: bits. Address field instruction length minus all other fields.
-
Signed -bit immediate or offset: to . Unsigned: to .
-
Branch target: . Read whether PC is already incremented.
-
Expanding opcode: -bit primary opcode, instructions used at that level, -bit field given up: next level has at most instructions. Work level by level; to fit a lower level you may need to reserve whole patterns.
-
Little-endian: least significant byte at the lowest address.
-
: 3-address ADD Z, A, B; 2-address MOV Z, A; ADD Z, B; accumulator LOAD A; ADD B; STORE Z; stack PUSH A; PUSH B; ADD; POP Z. Stack binary ops pop , then , push op .
ALU and control unit design
| Item | Formula |
|---|---|
| -bit two's complement range | to |
| Overflow (signed add) | ; same-sign operands give a different-sign result |
| Carry flag (unsigned) | carry out of the top bit |
| Negate | invert all bits, add 1 |
| Sign extension | copy the sign bit into new high bits (value unchanged) |
| Arithmetic shift right by 1 | floor division by 2, sign bit kept |
| Product width | bits gives bits |
Adders:
- Ripple carry, carry delay per full adder, sum delay : at , top sum at . Delay is .
- Carry lookahead: , , .
- ; .
- Single-level CLA: in 1 gate delay, carries 2 more, sums 1 more. Fan-in grows with .
- CLA blocks in ripple: first block carry at , then per block.
- Carry select: upper blocks compute both carry-in cases; a mux chain picks. About one block ripple plus one mux per later block.
Booth (radix 2), pair with : 00 or 11 shift only; 01 add multiplicand; 10 subtract multiplicand. Alternating bits are the worst case.
Control units:
| Hardwired | Microprogrammed | |
|---|---|---|
| Speed | faster | slower (control memory read per step) |
| Change | redesign logic | rewrite control memory |
| Typical ISA | RISC | CISC |
| Sequencing | -bit step counter + decoder | microprogram counter + opcode mapping |
Microinstruction width, control signals:
- Horizontal: bits for control, many signals in parallel.
- Fully vertical (one signal at a time, plus a "none" code): bits; needs a decoder.
- Grouped encoding with mutually exclusive groups : bits.
- Next-address field: bits for control words. Condition select: bits.
- Control memory size word width.
Memory hierarchy and cache
Address split for capacity , block , associativity , address width :
| Field | Bits |
|---|---|
| Offset | |
| Sets | |
| Index | (0 if fully associative) |
| Tag |
- Tag store lines (tag + valid + dirty + replacement bits). Lines .
- A -way cache needs tag comparators and a -to-1 mux. Exact LRU per set: bits.
- VIPT without aliasing: page size.
- Chips needed .
Average access time:
| Organisation | One level | Two levels |
|---|---|---|
| Hierarchical (miss pays every level visited) | ||
| Simultaneous (served by the first level that has it) |
- above is the local L2 miss rate. Global L2 miss rate , so hierarchical .
- Given a "miss penalty": .
- Block of words, bus cycles (1 for address, 1 per word): non-interleaved ; -way interleaved .
- TLB plus physical cache: for an -level page table walk with uncached entries.
Write policies:
| Policy | Bus traffic per reference |
|---|---|
| Write-through, no-write-allocate ( bytes per write) | |
| Write-back, write-allocate |
- Usual pairs: write-through with no-write-allocate and a write buffer; write-back with write-allocate.
- Write-back read miss with dirty victim: two block transfers.
Misses (3C): compulsory depends only on distinct blocks touched; capacity on size; conflict is the extra over fully associative, cut by associativity. Larger blocks first cut misses, then raise misses and penalty.
Array loops, row-major , element size , address :
- Row-wise read, cold cache: misses .
- Column-wise: if every block touched by one column stays resident until the next column, misses ; if each column pass evicts its own blocks, every access misses (). Otherwise simulate.
- Two arrays exactly a multiple of the cache size apart thrash a direct-mapped cache; 2-way fixes it.
Inclusion: inclusive means every L1 block is also in L2 (L2 eviction invalidates L1); exclusive holds L1 + L2 distinct data. A victim cache keeps recent L1 evictions.
I/O interface: interrupts and DMA
| Quantity | Formula |
|---|---|
| Polling CPU fraction | polls per second cycles per poll clock rate |
| Interrupt CPU fraction | cycles per interrupt clock |
| DMA CPU fraction | setup and completion cycles clock |
| Burst DMA, CPU off the bus | bus cycle |
| Cycle stealing, fraction of bus cycles | bus cycle time |
| Max rate under a CPU budget | clock cycles per interrupt bytes per interrupt |
| Serial line characters per second | bits per second bits per character |
- Programmed I/O: CPU busy-waits and moves every word. Interrupt-driven: CPU moves every word inside the ISR. DMA: CPU only sets up and handles the completion interrupt.
- Interrupts are recognised at the end of an instruction; PC and status are saved first.
- Interrupt latency for a lower-priority device (non-nested) rest of current instruction every higher ISR (entry + body + return) its own entry.
- Priority: daisy chain by position (nearest the CPU wins); software polling by polling order; vectored interrupts give the ISR address directly.
- DMA modes: burst (CPU locked out for the block), cycle stealing (one word per stolen cycle), transparent (idle bus cycles only, CPU never slowed). Bus request and grant first; interrupt at block end.
- Memory-mapped I/O uses ordinary load and store; isolated I/O uses IN/OUT and a separate address space.
Instruction pipelining and hazards
| Quantity | Formula |
|---|---|
| Clock period | (latch delay ) |
| Non-pipelined time per instruction | |
| instructions, stages, no stalls | |
| With stalls | |
| Speedup | ( if balanced, no overhead) |
| Efficiency | speedup |
| CPI with stalls | |
| Speedup with stalls (balanced) | depth |
| Stages needed for clock | smallest with |
Branches:
- Resolved at the end of stage : penalty cycles if the guess is wrong.
- Predict not-taken: CPI .
- Dynamic predictor with accuracy : CPI (plus any cost on correct taken predictions if stated).
- Delay slot instruction always executes. Earlier resolution, BTB and filled delay slots cut the penalty; deeper front ends raise it.
Data hazards in the classic 5-stage pipeline (IF, ID, EX, MEM, WB):
| Producer to next instruction | No forwarding, split-cycle register file | No forwarding, no split | Full forwarding |
|---|---|---|---|
| ALU to ALU | 2 stalls | 3 stalls | 0 |
| Load to use | 2 stalls | 3 stalls | 1 stall |
| Producer two instructions back | 1 stall | 2 stalls | 0 (from MEM/WB) |
- Only RAW hazards occur in an in-order 5-stage pipeline. WAR and WAW appear with out-of-order or multi-cycle units; register renaming removes both.
- Structural hazard: shared resource in the same cycle, such as one memory port for IF and MEM (1 stall per load or store), or a non-pipelined multi-cycle unit (next user waits until it frees).
- Unequal stages: the slowest stage sets the clock. Splitting it helps only until another stage becomes the slowest.
- Deeper is not always better: always, and hazard penalties grow with depth.
- "Speedup for large " with stalls: .