Skip to content
BetterDL

Arithmetic logic unit (ALU)

Also called: arithmetic-logic unit, arithmetic and logic unit

A combinational circuit that performs one of several arithmetic or logic operations on its inputs, such as ADD, SUB, AND or OR, chosen by an opcode.

The arithmetic logic unit (ALU) is the part of a processor that actually computes: adding, subtracting, ANDing, ORing, comparing. It's a combinational circuit, so its output depends only on its current inputs; a register outside it holds the result.

How it's organized:

  1. Every operation runs at once. An adder/subtractor, an AND unit and an OR unit (and any others) all compute from A and B in parallel.
  2. A multiplexer picks the result. The opcode, or function select code, drives the MUX select lines, so only the chosen unit's answer reaches the output Y (result multiplexer).
  3. Flags describe the result: N, Z, C and V.

The ALU in this course uses a 2-bit opcode F1F0:

  • 00 AND, 01 OR, 10 ADD, 11 SUB
  • SUB = drives the controlled inverters on B and the carry-in C0, turning the adder into a subtractor

An n-bit ALU is n identical bit slices side by side, sharing the opcode lines, with the adder carries chained between slices. Logic operations work on each bit independently; only ADD and SUB use the carry chain.

To add an operation: add its unit, widen the opcode if needed (k select bits give 2ᵏ operations), widen the MUX, and re-derive every control signal from the new opcode table.

F0ABY

Worked example

Example

Running the 4-operation ALU

A = 0101, B = 0011, with each opcode in turn.

  1. 1.

    00 AND: 0001.

  2. 2.

    01 OR: 0111.

  3. 3.

    10 ADD: 5 + 3 = 8 = 1000.

  4. 4.

    11 SUB: 0101 + 1100 + 1 = 18 = 1 0010. Keep 4 bits: 0010 = 2 = 5 − 3.

  5. 5.

    All four results were computed every time; the opcode only chose which one to output.

Common mistakes

  • Thinking the ALU only runs the selected operation. All the units compute every time.

  • Assuming k opcode bits select k operations. They select up to 2ᵏ.

  • Thinking the ALU stores its result. It's combinational; a register holds the output.

Practice Arithmetic logic unit (ALU)

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Arithmetic logic unit (ALU) is taught in Adders and ALUs and Basic CPU / Computer Architecture.