Lesson 5: Combinational Logic & the ALU
We saw logic gates that compute AND, OR, and NOT, and we saw how numbers are written in binary. Now we'll join the two: take simple gates and build from them a circuit that truly computes — that adds two numbers. Every circuit in this lesson is 'combinational logic': the output depends only on the c
If you give a few logic gates the same bits, they always return the same answer — they have no memory. In this lesson we combine such gates into a little adding machine, and then into the CPU's big calculator called the ALU.
- Combinational Logic
- A circuit whose output is determined solely by the inputs at the present moment, with no memory of a prior state. The same inputs always yield the same output.
- Half-Adder
- A circuit that adds two single bits and outputs two bits: a sum from an XOR gate, and a carry from an AND gate.
- Full-Adder
- A circuit that adds three bits — two input bits and a carry-in — and outputs a sum bit and a carry-out bit.
- Carry
- The bit you 'carry' to the next column when the current column's sum exceeds what a single digit can hold (in binary, when the sum is 2 or more).
- Ripple-Carry Adder
- A chain of full-adders, one per bit column; each stage's carry-out feeds the next stage's carry-in and 'ripples' along the chain.
- Multiplexer
- A selector: a circuit with several input lines that picks one of them to pass to the output, according to select lines that act as a steering switch.
- ALU (Arithmetic Logic Unit)
- A large combinational circuit at the heart of the CPU that performs arithmetic and logic operations (add, subtract, AND, OR, comparisons). An opcode selects which operation runs.
- Opcode
- A short pattern of bits that tells the ALU which operation to perform on the inputs — like a menu number that selects the desired action.
- Status Flags
- Single bits the ALU sets to report on the result: a zero flag when the result is 0, a carry flag when a carry spilled past the number's width.