Step 6 of 6 in Computer Science
Computer Architecture
Logic gates up to memory hierarchies and instruction sets. Citation needed
The whole, before the parts
Computer architecture is the tower of abstractions that turns switching electricity into a machine that runs any program. The single idea that carries it is that each layer is built from nothing but the layer below: switches make gates, gates make circuits that add and remember, those circuits make a machine that endlessly fetches and obeys instructions, and the instructions are the interface on which all software stands. Every layer can be understood — and verified — while ignoring the ones beneath it. Citation needed
Terminology and core concepts
-
Binary numbers and two's complement
Hardware represents everything in bits, with negative integers in two's complement: a number's negation is its bits flipped plus one, which lets a single adder circuit serve addition and subtraction alike. Citation needed
- How is a number negated in two's complement?
- flip every bit, then add one Citation needed
- Why does two's complement exist at all?
- so one adder handles addition and subtraction Citation needed
- What does the leading bit indicate in two's complement?
- the sign — 1 means negative Citation needed
- What is the range of an 8-bit two's complement integer?
- -128 to 127 Citation needed
- What is overflow?
- a result too large for the bits, wrapping around Citation needed
-
Logic gates
A gate is a switch-built device computing one truth-functional connective on voltages read as true and false — AND, OR, NOT in hardware — and the NAND gate alone suffices, since every truth-functional connective can be built from it. Citation needed
- What does a gate compute?
- one truth-functional connective, in voltage Citation needed
- What does a NAND gate output?
- false only when both inputs are true Citation needed
- How is NOT built from NAND?
- feed the input to both NAND inputs Citation needed
- Why does NAND's sufficiency matter to manufacturing?
- a chip needs only one perfected gate type Citation needed
- What does a truth table specify about a circuit?
- its output for every combination of inputs Citation needed
-
Combinational circuits
A combinational circuit's outputs depend only on its present inputs — no memory — and the workhorse example is the full adder, which adds two bits plus a carry; chained, full adders add whole numbers, and with two's complement the same chain subtracts. Citation needed
- What defines a combinational circuit?
- outputs depend only on current inputs Citation needed
- What are a full adder's three inputs?
- two addend bits and a carry in Citation needed
- What are its two outputs?
- a sum bit and a carry out Citation needed
- How do full adders add 32-bit numbers?
- 32 of them chained, each carry feeding the next Citation needed
- What does a multiplexer do?
- selects one of several inputs by a control value Citation needed
-
Memory and the clock
Feed a circuit's output back into itself and it can hold a bit — that loop is the flip-flop, the unit of hardware memory; a clock then beats time, letting every flip-flop update once per tick so the machine moves in discrete, orderly steps. Citation needed
- What circuit trick lets hardware remember?
- feeding a circuit's output back into itself Citation needed
- What does a flip-flop store?
- one bit Citation needed
- What does the clock impose on the circuit?
- discrete steps — state changes only on the tick Citation needed
- What is a register?
- a row of flip-flops holding one machine word Citation needed
- What bounds how fast the clock may tick?
- the slowest signal path between flip-flops Citation needed
-
The stored-program machine
The von Neumann design keeps instructions in the same memory as data — programs are data, cast in hardware — and runs an endless fetch-decode-execute cycle: fetch the instruction the program counter points at, decode what it asks, execute it, and advance the counter. Citation needed
- Where does a stored-program machine keep instructions?
- in the same memory as data Citation needed
- What does the program counter hold?
- the address of the next instruction Citation needed
- Which step begins the basic instruction cycle?
- fetch Citation needed
- In the basic instruction cycle: fetch, […], execute.
- decode Citation needed
- Which step follows decoding in the basic instruction cycle?
- execute Citation needed
- How does a jump instruction change the cycle?
- it writes the program counter instead of advancing it Citation needed
- What earlier idea does storing programs in memory embody?
- programs are data Citation needed
-
The instruction set architecture
The instruction set architecture is the hardware's interface: the instructions, registers, and memory model software may rely on — so chips can be redesigned freely underneath while old programs keep running, the clearest industrial payoff of abstraction there is. Citation needed
- What does an instruction set architecture specify?
- the instructions, registers, and memory model software may use Citation needed
- What does it deliberately hide?
- the circuit-level implementation Citation needed
- Why do decades-old programs run on new chips?
- the instruction set interface was kept stable Citation needed
- What typically distinguishes a RISC-style design?
- few simple instructions, uniform in format Citation needed
- What does a compiler target?
- the instruction set, not the circuitry Citation needed
-
The memory hierarchy
Fast memory is small and expensive, large memory is slow, so machines layer them — registers, caches (small fast copies of recently used memory), main memory, disk — and the scheme works because programs exhibit locality: they reuse what they just touched and what sits next to it. Citation needed
- What trade-off forces a memory hierarchy?
- fast memory is small; large memory is slow Citation needed
- What does a cache hold?
- copies of recently used memory Citation needed
- What is temporal locality?
- what was just used will likely be used again Citation needed
- What is spatial locality?
- neighbours of what was used will likely be used Citation needed
- What is a cache miss?
- a lookup not found in the cache, fetched from below Citation needed
- Why does traversing an array beat chasing pointers, in the hardware's eyes?
- contiguous access rides spatial locality; scattered nodes miss Citation needed
-
Pipelining
Pipelining overlaps the cycle's stages like an assembly line — while one instruction executes, the next is decoded and a third fetched — multiplying throughput without speeding any single instruction, at the price of hazards when one instruction needs a result its neighbour has not produced. Citation needed
- What does pipelining overlap?
- the cycle stages of consecutive instructions Citation needed
- Does pipelining speed up a single instruction?
- no — it raises throughput, not instruction speed Citation needed
- What is a hazard?
- an instruction needing a result not yet produced Citation needed
- Why are branches costly in a pipeline?
- until the branch resolves, the fetched successors may be wrong Citation needed
- What does branch prediction gamble on?
- which way the branch will go, to keep the pipeline full Citation needed
Problems that prove it
-
Write -37 as an 8-bit two's complement number, then add it to 50 and check.
Drills: negation by flip-and-add-one, and subtraction falling out of addition.
Derivation steps
- 37 in binary, 8 bits: 00100101.
- Flip: 11011010. Add one: 11011011. That is -37.
- 50 is 00110010. Add: 11011011 + 00110010 = (1)00001101, discarding the ninth bit.
- 00001101 = 13, and 50 - 37 = 13. ✓
- No subtractor was used — the adder did it, which is the design's whole point.
Citation needed
-
Build a full adder's truth table from its definition and read off the two output functions.
Drills: from arithmetic requirement to truth-functional circuit.
Derivation steps
- Inputs a, b, carry-in c; the true sum is the count of ones, 0 to 3, written in two bits.
- Count 0 → sum 0 carry 0; count 1 → sum 1 carry 0; count 2 → sum 0 carry 1; count 3 → sum 1 carry 1.
- Sum bit is 1 when an odd number of inputs are 1: exclusive-or of all three.
- Carry-out is 1 when at least two inputs are 1: (a AND b) OR (c AND (a XOR b)).
- Both are truth-functional, so both are gates — the adder is logic, nothing more.
Citation needed
-
Trace two fetch-decode-execute cycles on a toy machine: program counter at 0; address 0 holds "LOAD R1, 20", address 1 holds "ADD R1, R2"; address 20 holds the value 7; register R2 holds 5.
Drills: the cycle as bookkeeping — counter, instruction, effect, repeat.
Derivation steps
- Fetch: read address 0 — "LOAD R1, 20". Counter will advance to 1.
- Decode: a load — move memory contents into a register.
- Execute: R1 ← memory[20] = 7.
- Fetch: read address 1 — "ADD R1, R2". Counter advances to 2.
- Decode and execute: R1 ← R1 + R2 = 7 + 5 = 12.
- State after two cycles: counter 2, R1 = 12, R2 = 5 — and the instructions were just bytes in the same memory as the 7.
Citation needed
-
A five-stage pipeline runs instructions that each take 5 ns unpipelined. Estimate the time for 1,000 instructions with and without the pipeline, ignoring hazards.
Drills: throughput versus single-instruction speed.
Derivation steps
- Unpipelined: 1,000 × 5 ns = 5,000 ns.
- Pipelined, each stage 1 ns: the first instruction completes at 5 ns.
- Thereafter one instruction completes every 1 ns: 999 more ns.
- Total ≈ 1,004 ns — nearly 5× throughput, though each instruction still takes 5 ns start to finish.
- Hazards would insert stalls and eat into the 5×; the estimate is the ceiling.
Citation needed
Sources
- Noam Nisan and Shimon Schocken, The Elements of Computing Systems — the whole tower built by hand, NAND to a working computer.
- David Patterson and John Hennessy, Computer Organization and Design — the standard text on instruction sets, pipelines, and caches.
- Charles Petzold, Code: The Hidden Language of Computer Hardware and Software — relays to processors, told so the feedback-loop memory trick actually lands.
Learning path
Continue through Computer Science in order, using the concepts above to connect this topic to the next.