Meet the ALU
Every block in this theme was practice for one machine: the arithmetic logic unit, the calculating heart of every processor — and it's still just combinational logic.
Built from first principles. (A concept tour now; you'll build one in Theme 11.)
Before you start
What you need first
- Adder/subtractor — the arithmetic path.
- Multiplexer — to select which result comes out.
- Logic gates — AND/OR/XOR as bitwise operations.
What you'll be able to do
- Say what an ALU is and read its block symbol.
- See how it's built: parallel units + a MUX picked by the opcode.
- Name the common status flags and why the ALU is combinational.
What an ALU is
An ALU (arithmetic logic unit) takes two operands A and
B, an opcode that says which operation to perform, and produces
a result Y plus a few status flags. It can add,
subtract, AND, OR, XOR, compare — the menu the processor's instructions are built from.
A small ALU might offer 8 operations, chosen by a 3-bit opcode (23 = 8). Bigger ALUs simply have a wider opcode.
How it's built — from the blocks you already have
The trick: run all the operations at once, in parallel, then use a MUX to keep only the one the opcode asked for. The adder/subtractor, the AND, the OR, the XOR each compute their result; the opcode is the MUX's select line.
The status flags
Alongside the result, an ALU reports a few one-bit flags describing it. These are what later instructions (like "branch if equal") test:
| Flag | Set when… |
|---|---|
| Z — Zero | the result is all 0s |
| C — Carry | the addition produced a carry-out (unsigned overflow) |
| N — Negative | the result's sign bit (MSB) is 1 |
| V — Overflow | a signed result fell outside the representable range |
✏️ Try it yourself
(a) What three kinds of input does an ALU take? (b) Which block selects which operation's result becomes Y? (c) What does the opcode act as? (d) Which flag is set when the result is zero? (e) Why is the ALU called combinational?
Recap — the whole topic on one screen
| Idea | What you own now |
|---|---|
| ALU | operands A,B + opcode → result Y + flags |
| How built | parallel units (add/sub, AND, OR, XOR) → MUX picked by opcode |
| Opcode | = the MUX select lines |
| Flags | Z (zero), C (carry), N (negative), V (overflow) |
| Combinational | no memory — output depends only on present inputs |