notesonly.in

One notebook for every subject — open it anywhere.

Log in

ALU Design and Datapath: Complete Beginner's Guide

The ALU (Arithmetic Logic Unit) is the processor part that calculates: it adds, subtracts, compares and applies logic operations like AND, OR and XOR to binary numbers. Every computation, from spreadsheet totals to game physics, passes through an ALU.

The datapath is the network of registers, buses and units through which data flows during an instruction. Understanding them reveals how instructions become signals: two numbers travel from registers into the ALU, combine, and land back in a register within one clock cycle.

Key Concepts

  • ALU: a combinational circuit with two data inputs, a result output, operation-select control lines and status flags.
  • Opcode: the instruction bit pattern telling the control unit which ALU operation to perform.
  • Register file: fast CPU storage holding the operands and results the ALU works on.
  • Full adder: the one-bit block adding two bits plus carry-in to give sum and carry-out; chaining builds multi-bit adders.
  • Flags: single-bit indicators set after an operation: Zero, Carry (unsigned overflow), Negative and Overflow (signed overflow).
  • Multiplexer: a selector routing one of several inputs to the output; it chooses which operation result leaves the ALU.

How It Works

An ADD instruction executes in a choreographed sequence. First, the register file places the operands onto the ALU's A and B inputs. The control unit decodes the opcode and sets control lines for addition, routing the adder's output — not the AND/OR outputs — to the result bus. A ripple-carry adder adds bit by bit from the least significant bit upward, each stage passing its carry onward. Flag logic sets Zero if the result is all zeros and Carry if the last stage produced a carry. Finally, the result is written to the destination register on the next clock edge.

Subtraction reuses the adder with the two's complement of B; logic ops run in parallel bit-slices, the multiplexer picking the result. This hardware sharing lets one ALU serve dozens of instructions.

Worked Example

Add 6 (0110) and 5 (0101) in a 4-bit ALU. Bit 0: 0 + 1 = 1, carry 0. Bit 1: 1 + 0 = 1, carry 0. Bit 2: 1 + 1 = 0, carry 1. Bit 3: 0 + 0 + 1 = 1, carry 0. Result: 1011 binary = 8 + 2 + 1 = 11 decimal, and indeed 6 + 5 = 11. Zero and Carry flags stay clear, confirming the true result fits in 4 bits.

Common Misconceptions

  • The ALU decides what to compute. The ALU is dumb hardware; the control unit decodes the instruction and selects the operation.
  • A bigger ALU is always faster. Speed also depends on adder design: ripple-carry delay grows with width, while carry-lookahead trades gates for speed.
  • The datapath is the whole CPU. The datapath moves data; the control unit generates timing and select signals. Neither works alone.

Real-World Applications

  • General processors: every CPU core uses ALUs to execute integer instructions.
  • Graphics and AI chips: GPUs and neural accelerators are vast arrays of ALU-like units.
  • Digital signal processors: specialized ALUs with multiply-accumulate units power audio and modem processing.
  • Calculators and embedded chips: even simple microcontroller ALUs handle sensor readings.

The ALU and datapath turn instructions into physical computation: operands in, operation selected, result with flags out. This rhythm, repeated billions of times per second, is every processor's heartbeat.