Skip to main content
Be Bitwise

Add Two Numbers

Load two values into registers and add them together. The simplest possible program.

Every CPU operation follows the same cycle: fetch an instruction from memory, decode what it means, execute the operation, then write the result back. This simulation strips that down to the absolute basics — loading immediate values into registers and performing arithmetic. By stepping through each phase you can see exactly what happens inside the CPU on every tick of the clock.

Simulator

Loading simulator...

Walkthrough Guide

  1. 1

    Load the first value

    Do this: Step through the first MOV instruction

    Watch for: R0 changes from 0 to 5

    MOV R0, #5 copies the immediate value 5 into register R0. The CPU fetches the instruction bytes from memory at the address in PC, decodes them as a MOV, then writes 5 into R0 during the writeback phase.

  2. 2

    Load the second value

    Do this: Step through the second MOV instruction

    Watch for: R1 changes from 0 to 3

    MOV R1, #3 works identically — the CPU fetches, decodes, and writes 3 into R1. Notice the PC has incremented by 2 after each instruction because each instruction is 2 bytes wide.

  3. 3

    Add the two registers

    Do this: Step through the ADD instruction

    Watch for: R0 changes from 5 to 8

    ADD R0, R1 sends both register values into the ALU, which computes 5 + 3 = 8. The result is written back into R0, replacing its previous value. R1 is unchanged because it was only read, not written.

  4. 4

    Halt the CPU

    Do this: Step through the HALT instruction

    Watch for: The CPU stops executing and the halted flag is set

    HALT tells the CPU to stop fetching instructions. Without it the CPU would keep reading whatever bytes come next in memory, interpreting them as instructions — which would produce unpredictable behaviour.

Objectives

  • •Watch R0 change from 0 to 5 after the first MOV
  • •Watch R1 change from 0 to 3 after the second MOV
  • •See R0 become 8 after the ADD instruction
  • •Notice how the PC increments by 2 after each instruction

Hints

  • Step through one instruction at a time and watch the register values change