Master the fundamental concepts of digital logic & boolean algebra through this focused micro-challenge.
A 4-bit ALU performs arithmetic and logic on two nibble-wide operands. A opcode line (often fed through a MUX) selects the operation: ADD, SUB, AND, OR, XOR, or NOT.
cLoading…
The carry-out from bit 3 becomes the C flag your CPU will later branch on.
Real ALUs export status bits:
For example, 7 + 1 on four signed bits overflows because 0111 + 0001 wraps to 1000 (-8 in two's complement).
For this exercise, you will combine your adder, logic gates, and MUX into one selectable ALU. This task asks you to produce both the result nibble and flag bits, because the branching and pipeline tasks downstream read those flags to decide jumps.
Keep the relevant datasheet, ISA manual, or architecture textbook chapter open while you implement. When your output disagrees with the reference trace on the same program, the bug is usually a mis-decoded opcode, a stale register read, or a flag bit left unchanged after arithmetic.
For this exercise, you will use those habits while implementing the requirement in the starter code. Microarchitectural product names change across CPU generations, but the control ideas (fetch, bypass, cache lines, vector lanes) stay stable enough to debug from first principles.
Build 4-bit ALU supporting ADD, SUB, AND, OR, NOT, XOR operations.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github