---
title: "Computer Architecture overview"
description: "Watch a word hold a number, count, overflow, round, and get added by gates. Binary place value, two's complement, IEEE 754 floats, and logic gates, animated."
source: https://vizlearn.app/cs/architecture
---

# Computer Architecture Visualizations

A computer has no idea what a number is. It has a fixed row of positions, each holding one of two states, and a set of rules for what that row means. Everything else — that 255 plus 1 is 0, that a negative number starts with a 1, that subtraction is just addition — follows from those rules and from the fact that the row never gets any longer.

These lessons animate the row itself. The bits stay in fixed, labelled positions, the word boundary is drawn on screen, and every carry that leaves the word is shown leaving rather than quietly discarded.

## Compare the lessons

| Lesson                    | Main question                             | What changes                                         | Where it breaks                        |
| ------------------------- | ----------------------------------------- | ---------------------------------------------------- | -------------------------------------- |
| Binary Numbers            | What does a row of bits mean?             | position k is worth 2^k                              | 255 + 1 wraps to 0                     |
| Two's Complement          | How does that row hold a negative number? | the top position is worth −2⁷ instead of +2⁷         | 127 + 1 wraps to −128                  |
| Floating Point (IEEE 754) | How does that row hold a fraction?        | the row splits into three fields and the point moves | 0.1 + 0.2 is not 0.3                   |
| Boolean Logic & Gates     | What actually performs the addition?      | the wiring between four-row lookup tables            | one wrong gate is right on 3 rows of 4 |
| Instruction Execution     | What makes a word an instruction?         | one loop reads memory and one register says where    | a stored number gets executed          |
| CPU Pipeline              | Why does overlapping five instructions not make them five times cheaper? | five stages run at once, one instruction issued per cycle | a `lw` feeding the next instruction costs a cycle no wiring wins back |
| Cache Hierarchy           | Why do twelve loads cost 804 cycles or 3072? | how many lines those loads spread across             | stride 4 costs 3072 cycles, stride 1 costs 804 |
| Branch Prediction         | How does a machine get past an `if` it has not decided yet? | it guesses, and discards the work when it guessed wrong | an unpredictable branch throws away a fifth of the run |

The first two lessons teach one idea at two settings. Place value assigns a weight to each position and adds up the positions holding a 1. Two's complement changes exactly one of those weights — the leftmost — and lets everything else stand. That is why the second lesson can hand signed numbers to a plain unsigned adder and get correct answers without a single sign test.

Floating point is the first real break from that. Instead of assigning fixed weights to fixed positions, it cuts the row into a sign, an exponent, and a fraction, and lets the exponent decide where the point sits. The payoff is enormous range from a short word; the price is that the representable values stop being evenly spaced, so most decimals land between two of them and get quietly rounded. **Boolean Logic & Gates** goes the other way and opens the adder up: the carry the earlier lessons treat as a rule is, in hardware, one AND gate and one OR gate.

## A recommended order

Start with **Binary Numbers**. Convert a value both directions until the round trip feels automatic: dividing by 2 peels off the lowest bit, and adding the weights of the set positions puts the number back together. Then run the counting mode and watch a carry ripple through a run of 1s. The moment worth waiting for is 255 plus 1, where all eight positions clear and the carry has no ninth position to land in.

Then open **Two's Complement**. It assumes you can already read a word, and it moves straight to the one weight it changes. Negate a few values, then add a negative to a positive and watch the adder never inspect a sign. Its overflow case is the same story as the wrap you already saw, one position over: the answer needs a bit the word does not have.

Then **Floating Point (IEEE 754)**, which is where the fixed row finally stops being a fixed row. Store 0.1 and watch its binary expansion refuse to terminate, then read back what the bits actually hold. Switch to the add variant for `0.1 + 0.2` and load the binary32 scenario immediately afterwards: the same sum, the same code, one field width wider, and the verdict flips from false to true. That flip is the point — there is no rule about tenths, only about where the rounding happens to land.

Then **Boolean Logic & Gates**, which goes one level below the number lessons. They all treat column addition as a given; this one builds it out of parts. A gate is a four-row lookup table, wiring two of them together forces a new table nobody chose, and the table that falls out is the one that says 1 + 1 = 10. Load the broken-adder scenario before you leave: swapping a single gate leaves three of the four rows correct, which is the most useful thing in the category to have seen once.

**Instruction Execution** is where the category turns from what a word means to what a machine does with one. The same fixed-width word that held a number in the first three lessons now holds an opcode and three fields, and a loop of four stages runs it: fetch the word the program counter names, advance the counter, cut the word into fields, do what the opcode says. Watch the jump instruction twice — once taken, once not, same word both times — and then load the self-modifying scenario, where a store lands on the program's own HALT and the machine executes the number without complaint. Nothing marks a word as code; only the program counter reaching it does.

Then **CPU Pipeline**, which takes that one-instruction-at-a-time loop and runs five of them at once — one in each stage. Watch cycle 5 of the default run, where that one column reads `WB MEM EX ID IF` — five instructions in the machine on a single clock; that frame is the whole idea. Then watch it stop: the fourth instruction needs a register the third has not written yet, so it waits two cycles and the execute stage sits empty. Flip the hardware selector to Forwarding and the same five instructions finish in 10 cycles instead of 13, because a result can be taken out of a pipeline register instead of the register file. One stall survives, and it is the load — its value does not exist until after the memory stage, and no wire runs backwards in time.

**Branch Prediction** is the first lesson here where the machine is allowed to be wrong on purpose. A conditional branch is not resolved until it is several stages deep, and the fetcher cannot wait that long, so it guesses and keeps going — then scraps everything it fetched if the guess was wrong. Run the default loop and watch the two-bit counter pay for its own stubbornness twice at the start and collect on it at every loop re-entry afterwards. Then load the sorted and shuffled data scenarios back to back: identical code, identical values, one of them in order, and the run costs 52 cycles against 62. That is the real answer to why sorting an array first can make the loop over it faster.

Finish with **Cache Hierarchy**, the one lesson here where the code is not the story. Every run executes the identical `load()`; what changes is which addresses it is handed, and that alone moves the bill by a factor of four. Watch the first miss carefully — one request, four words back — and then switch to the stride-4 pattern and compare the cost ribbons: twelve loads either way, 804 cycles against 3072, because one run spreads them over three lines and the other over twelve. Load the conflict scenario before you leave and flip the mapping to 2-way, which fixes a cache that was thrashing while three of its four rows sat empty.

## What to watch

- Keep position and value apart. Bit 3 is an address; 8 is what that address is worth.
- Read the labels, not the shape. Bit 7 sits on the left, so positions count down as you read across, and weighting them the other way decodes the mirrored word.
- Watch what leaves the word. A carry that runs past the top position is dropped in silence and raises nothing. In the unsigned lesson that dropped carry is the wrap; in the signed one it is routine bookkeeping, and whether the answer is wrong is a separate test.
- Notice how few rules change between the first two lessons. Almost every property of binary arithmetic survives into signed arithmetic untouched.
- Watch where the spacing goes. Integers are evenly spaced by definition; floats are not, and the gap between neighbours doubles at every exponent step. That single fact explains rounding error, absorption, and why `==` is the wrong tool on a computed value.
- Watch where a rule stops being a rule. The carry in the first two lessons is something the algorithm does; in Boolean Logic & Gates it is a wire coming out of an AND gate.
- Watch which register is being written. In Instruction Execution the program counter is an ordinary register, and every loop, `if`, and function call in every language you use is some instruction writing to it.
- Watch the empty stage. A stall is not a slow instruction; it is a cycle in which one stage of the machine does nothing at all, and the hole it leaves travels down the pipeline behind the instruction that caused it.
- Watch what gets thrown away. A mispredicted branch raises nothing, logs nothing, and returns the right answer; it just quietly redoes work it had already started. It is the most expensive thing a CPU does that a debugger will never show you.
- Watch the line, not the word. A cache never moves the word you asked for; it moves the whole line the word sits in, and every later word in that line rides along free. Half of what people call "optimising memory access" is just arranging to use all of a line you already paid for.

## All computer architecture visualizations

Pick a lesson below, change the value, and step through the trace beside its highlighted Python code.
