logic-circuits computer-architecture

Definition

Arithmetic Logic Unit

An arithmetic logic unit is a combinational circuit in a processor that applies one selected arithmetic or logical operation to its inputs.

Typical operations are addition, subtraction, AND, and OR. The selected operation is determined by control signals.

Control

The ALU takes two inputs and together with a control signal that selects the operation.

Control signalFunction
Addition
Subtraction
AND
OR

Flags

An ALU can also output status flags that summarise properties of the result.

FlagMeaning
the result is negative
the result is zero
the adder produces a carry out
signed overflow occurs

Implementation

One adder for addition and subtraction

A common implementation reuses one full adder for both addition and subtraction.

The key identity is:

So the circuit can:

  • pass unchanged for addition;
  • pass for subtraction;
  • use the control bit as the carry-in.

This lets one adder implement both operations.

Adding status flags

The ALU can be extended so that it outputs the flags together with the main result.

Overflow logic

The overflow flag is the most subtle part.

The logic can be read step by step.

  1. The right-most gate enables the overflow logic only for addition and subtraction.

  2. The middle gate checks whether the sign bit of the result differs from the sign bit of .

  3. The left XNOR gate captures the sign pattern that can overflow:

    • for addition, overflow is possible only when and have the same sign;
    • for subtraction, overflow is possible only when and have different signs.

Putting these conditions together yields the signed overflow flag .