logic-circuits

Definition

Arithmetic Logic Unit

An arithmetic logic unit is the heart of the processor that performs basic arithmetic and logic functions:

  • addition
  • subtraction
  • AND
  • OR

The ALU takes in two inputs and a control signal. The control signals determines the function to apply on the given inputs:

Control SignalFunction
Addition
Subtraction
AND
OR

The ALU can be extended to additionally output status flags:

FlagDescription
Result is Negative
Result is Zero
adder produces Carry out
Adder oVerflowed (signed, two’s complement)

Implementation

A way of implementing ALUs is to use a single adder for both subtraction and addition by introducing a multiplexer. This is possible since , which is equivalent to . Thus, if the control signal is , the negated value of is passed to the adder.

As said above, ALUs can be extended to output status flags:

The overflow part is a bit more tricky:

  1. The most right gate outputs true if the ALU is instructed to do addition or subtraction.
  2. The gate in the middle outputs true if the MSB of and the MSB of the sum are different.
  3. The XNOR gate on the left outputs true if there is an even number of true input signals. Thus, it is true if we do addition () and the MSBs of and are one, or it is true if we do subtraction and the MSBs of and be are different.