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.

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. 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.