ALU Design

Building a multi-function ALU with arithmetic, logic operations, flags, and status register.

The Arithmetic Logic Unit (ALU) is the computational core of every CPU. It combines adders, logic gates, and multiplexers to perform multiple operations (ADD, SUB, AND, OR, XOR, shifts) selected by control signals. The ALU also generates status flags (zero, carry, negative, overflow) that enable conditional branching. Designing an efficient ALU is a key step in building a CPU.

Objectives

  • Design an ALU that supports multiple arithmetic and logic operations
  • Use a multiplexer to select between operation results
  • Implement status flags: Zero (Z), Carry (C), Negative (N), Overflow (V)
  • Understand how the control unit selects ALU operations via opcode
  • Extend a basic ALU with shift and comparison operations

Key Takeaways

  • ALU computes all operations in parallel; MUX selects the result
  • Subtraction reuses the adder: A - B = A + ~B + 1
  • Flags (Z, C, N, V) enable conditional branching
  • ALU opcode comes from the control unit based on the instruction
  • ALU is the computational heart—everything else supports it

Applications

  • 74181 ALU IC: Historic 4-bit ALU IC that performs 16 arithmetic and 16 logic operations.
  • RISC-V ALU: Open-source CPU designs include well-documented ALU implementations.
  • GPU Shader Units: Thousands of simple ALUs process pixels and vertices in parallel.
  • DSP Processors: Specialized ALUs with hardware multiply-accumulate (MAC) units.

Practice Problems

Problem 1: Design a 4-operation ALU (ADD, SUB, AND, OR) with a 2-bit opcode. How many MUX inputs?

Problem 2: 8-bit ALU computes 0xFF + 0x01. What are the Z, C, and N flags?

Problem 3: How does the ALU perform subtraction using only an adder?

Problem 4: When does the Overflow (V) flag get set for signed addition?