Level 14: Heart of math
Open the level →Where it fits in the machine →
Task
Goal: build an 8-bit ALU (ADD, AND, OR, XOR, NOT, SHL, SHR); hint: decoder → operations → MUX.
The ALU (Arithmetic Logic Unit) is the heart of any processor. It performs 7 operations on two 8-bit numbers.
The main idea: scale comes from architecture, not from circuit size: the decoder turns an operation code into control signals, the operations run in parallel, the MUX picks the result, and the Zero flag reports a zero. The pattern decoder → operations → MUX will return in the processor's control unit.
Path to this level
The competencies this level develops and their formation levels.
Related Materials
- ALU8 — arithmetic logic unit
Solution for self-check
Try building the circuit yourself first. The solution below is a way to check yourself if you're stuck or have already solved it.
The in-game hint on this level inserts a scaffold: the circuit without one wire — the BusOR output into the multiplexer cascade. Connect it yourself: without it the OR operation returns garbage, and you can see why the decoder controls the selection.
What you should get: Opcode 0–6 picks one of the 7 operations, Result outputs its result, and Zero shows 1 when Result=0.
The ALU works in three stages: decoding → computation → selection.
- Decoding: split Opcode (the number 0–6) via Splitter into bits — they will drive the multiplexers.
- Computation: run all 7 operations in parallel, feeding inputs A and B to each block — ADDER8 (addition: A+B), BusAND (A&B), BusOR (A|B), BusXOR (A^B), BusNOT (~A), BusSHL (A<<1), BusSHR (A>>1). Electrical currents flow through all blocks at once: nothing is "called" one at a time — all the math runs in parallel, at every moment. Connect only input A to BusNOT: NOT is a unary operation.
- Selection: build a cascade of 6 BusMUXes. The first tier picks in pairs (ADD/AND, OR/XOR, NOT/SHL), the second and third tiers reduce to one result. The final MUX output is Result.
- Do not forget the Zero output: connect Result to BusZero — its output shows 1 when Result=0.
The opcode is read tier by tier, like digits of a number: bit 0 drives the pairs of the first tier, bit 1 — the pair winners, bit 2 — the final choice. Opcode 2 = 10: the one in the second bit wins at the second tier.
About the range boundary: 100+100 gives Result=200 — correct for unsigned numbers (0–255). But if the top bit is treated as the sign bit (two's complement), 200 reads as −56: that is signed overflow. Carry (going past 255) and sign overflow are different events: the vector 200+100 catches the first, the vector 127+1 — the second.
Check yourself
Why is BusNOT connected only to input A?
NOT is a unary operation: it needs a single argument, so input B stays free.