Build a CPU

Step 8 of 9

Run a program

Instruction, decode, control signals, result

Here is the whole machine, wired up: your ALU, the registers, the memory, and a control unit that turns each instruction into a set of switches.

Write a program and step through it. Every step shows you the instruction, the control signals it produced, what went into the ALU, and where the answer was written.

Nothing here is new. It is the parts you built, with something deciding what to connect to what.

This step builds on the ones before it, and will make a lot more sense after them. Go to Logic gates

Add two numbers from memory

Memory cell 0 and cell 1 each hold a number. Write a program that puts their sum into cell 2, then stops.

Your program is checked against more than one set of starting numbers, so it has to actually read them from memory.

Registers

R00
R10
R20
R30

Memory

0
7
1
5
2
0
3
0
4
0
5
0
6
0
7
0
8
0
9
0
10
0
11
0
12
0
13
0
14
0
15
0

Control signals

Step through the program to see them.

PCProgramControlRegistersregisterimmediateALUMemoryM U Xwrite backbranch
Instruction set
MOV Rd, valuePut a number straight into a register.
ADD Rd, Ra, RbRd = Ra + Rb
SUB Rd, Ra, RbRd = Ra - Rb
AND Rd, Ra, RbBitwise AND of two registers.
OR Rd, Ra, RbBitwise OR of two registers.
LOAD Rd, addressCopy a memory cell into a register.
STORE Rs, addressCopy a register into a memory cell.
JMP nJump to instruction n.
JZ Rs, nJump to instruction n, but only if Rs is zero.
HALTStop.
Not yet: it ran past the last instruction without a HALT.

Sign in to save your progress. The sandbox works either way.