Level 14: Heart of math
Task
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.
Related Materials
- ALU8 — arithmetic logic unit
Solution
Work in THREE stages:
STAGE 1 — Decoding: The Opcode input (number 0-6) tells which operation to run. Split Opcode via Splitter into bits — you will need them to control multiplexers.
STAGE 2 — Computation: Run ALL 7 operations in PARALLEL. Electrical currents flow through all 7 blocks simultaneously: each block continuously computes its result, and the BusMUX cascade at the end selects the one you need. Nothing is "called" one at a time — all the math runs in parallel, at every moment. Place on canvas and feed inputs A and B to each block: - ADDER8 (addition: A+B) - BusAND (bitwise AND: A&B) - BusOR (bitwise OR: A|B) - BusXOR (bitwise XOR: A^B) - BusNOT (bitwise NOT: ~A — only needs input A) - BusSHL (shift left: A<<1) - BusSHR (shift right: A>>1)
STAGE 3 — Selection: Build a cascade of 6 BusMUXes. The first level selects in pairs (ADD/AND, OR/XOR, NOT/SHL), the second and third levels reduce to one result. The final MUX output is Result.
Do not forget the Zero output: connect Result to BusZero — its output is 1 when Result=0.
About the range boundary: 100+100 gives Result=200 and Carry=0 — 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.