How a Computer Works

How a CPU Works

Watch a processor add 7 and 1. Change either number and follow a single RISC-V instruction down to the transistors that help produce the answer.

Read the steps

  1. Run one instruction

    Your budget needs one small addition. This is an RV32I teaching core. We follow that one instruction from the desktop into a deliberately simple 32-bit teaching processor.

  2. Enter the processor

    The package connects the silicon die to the motherboard. We select one core, not the whole chip at once.

  3. Fetch four bytes

    The program counter points to address 0x1000. Four bytes B3 81 20 00 arrive from the instruction memory. Little-endian means the least significant byte comes first.

  4. Decode the instruction

    The same bits mean add x3, x1, x2. The decoder selects x1 and x2 as sources, addition as the operation, and x3 as the destination.

  5. Read two registers

    The register file presents both 32-bit values to the arithmetic unit. A bit is a low or high voltage interpreted as 0 or 1.

  6. Enter the 32-bit adder

    Each column adds two bits and the carry from its neighbour. The low four columns are enlarged; all 32 columns still take part.

  7. Start at bit 0

    The least significant column runs first in this illustrative ripple-carry circuit. A carry means one unit in the next column.

  8. Follow the carry to bit 1

    A carry can make another carry. These transitions take time in a physical circuit. Here we isolate each column so you can follow it.

  9. Reach bit 2

    The carry now reaches the selected full-adder stage. Its propagate signal P is A XOR B. Its sum is P XOR carry-in.

  10. Open the carry gate

    N = NAND(P, carry-in). A second NAND combines N with NAND(A,B) to form carry-out. This is an actual gate in our chosen full-adder implementation.

  11. Follow the output node

    Two series nMOS transistors can connect node N to ground. Two parallel pMOS transistors connect it to the supply if either input is low. Voltage and conduction are shown together.

  12. Return to bit 3

    Follow the selected gate’s outgoing carry into the next column. In the default 7 + 1 example, the carry into bit 3 makes 0111 + 0001 become 1000.

  13. Write back the answer

    The completed 32-bit sum is written into x3. The next sequential instruction begins at 0x1004. Overflow beyond 32 bits is discarded by RV32I ADD.