Arithmetic Logic Unit
An ALU is the combinational core of a processor that performs arithmetic and logic operations selected by control lines.
What it does
The arithmetic logic unit takes two operands and a control code and produces a result plus status flags. A single opcode selects among operations such as add, subtract, AND, OR, XOR, and shift. The ALU is purely combinational: outputs depend only on current inputs, not on stored state.
Internal structure
A common design places an adder, logic gates, and a shifter in parallel, all fed the same operands, then uses a multiplexer to select which unit's result becomes the output. The control code drives both the operation-specific inputs and the final mux.
Add and subtract sharing
The adder handles both addition and subtraction by inverting the second operand and setting the carry-in, the two's-complement method. A single control bit switches between them, so no separate subtractor is needed.
Status flags
Alongside the result the ALU produces flags: zero when all result bits are 0, carry from the adder, negative from the sign bit, and overflow for signed range errors. Conditional branches read these flags.
In the CPU
The ALU sits at the center of the datapath. It computes memory addresses, evaluates comparisons for branches, and performs the arithmetic of the running program. Its speed is set largely by the adder's carry scheme.