01How Computers Work (online)

Part 05 of 12

From gates to an ALU

Make an actual computing block, then extend it to do several operations.

Six connected lessonsA diagram per chapterStart from first principles

The story before the details

A half adder is the first satisfying circuit to build because two everyday arithmetic facts line up perfectly with two Boolean functions: the low bit of A+B is XOR, and the carry-out is AND. But the half adder has a built-in limitation. A middle column can receive a carry from a previous column, so it needs three inputs, not two.

A full adder fixes that shortcoming. Chains of full adders build multi-bit arithmetic, stage by stage. The easiest topology is ripple carry: correct and comprehensible, yet increasingly slow as the number of bits grows. Modern hardware may use faster carry structures; the core arithmetic contract remains the same.

An ALU is not a single special gate. It is a composition of operation circuits and a selector. An instruction code eventually tells the selector whether to publish an addition result, a subtraction result, or a bitwise result. Flags provide useful properties of that published answer, including zero, sign, carry and overflow.

One-bit addition, diagram of connected labeled components
One-bit addition. Follow the arrows to identify where information travels and what each block contributes.

What you will discover

These six lessons are arranged so each one answers a question created by the previous one. Do not rush to the last lesson. If a concept feels opaque, use the checkpoint before continuing.

  1. 05.01The half adder↗Can two gates add two bits?
  2. 05.02The full adder↗What was the missing input?
  3. 05.03Ripple carry addition↗How do eight bits cooperate?
  4. 05.04Subtraction with XOR controls↗How can the same gates subtract?
  5. 05.05The arithmetic logic unit↗How does a processor choose ADD or AND?
  6. 05.06Flags from arithmetic↗How can later instructions know what happened?
Keep this in mind

Make an actual computing block, then extend it to do several operations. You should be able to explain each concept using only an input, a rule, an output, and any state that must be retained.