cpu simulator
Interactive online CPU simulator widget.
How to Use
Load the instructions into the RAM/Memory using the drop-down list.
If the instruction requires an operand value, the operand spinner will activate.
To clear an instruction, click the 'x'.
Click the Run button for automatic execution.
Click the Step button to control the execution.
Click the Reset button to reset the simulator to it's original state.
The simulation will run through the Fetch-Decode-Execute cycle repeatedly until it fetches, decodes and executes a
HALT instruction. The blue information panel will describe the CPUs task and the Output Console will show any output from the OUT instruction. If the program uses the INP instruction, a modal window will appear for your input. Watch the Program Counter (PC), the Current Instruction Register (CIR) and the Accumulator (ACC) as the CPU cycles.Instruction Set
Command
Description
Example
LOADLoads a value from a specific memory address into the Accumulator.
LOAD 5ADDAdds the value at a specific memory address to the value in the Accumulator.
ADD 6SUBSubtracts the value at a specific memory address from the value in the Accumulator.
SUB 6STOREStores the current value of the Accumulator into a specific memory address.
STORE 5INPUTPauses the program and asks the user to enter a number. The number is stored in the Accumulator.
INPUTOUTOutputs the current value of the Accumulator to the console.
OUTHALTStops the program execution immediately.
HALTJUMPUnconditionally jumps to a specific memory address (changes the Program Counter).
JUMP 0IF ZEROJumps to a specific memory address ONLY if the value in the Accumulator is 0.
IF ZERO 4Sample Programs to try
1
Add Two Inputs
Asks the user for two numbers, adds them, and outputs the result.
INPUT; STORE 10; INPUT; ADD 10; OUT; HALT2
Subtract Two Inputs
Asks for two numbers, subtracts the second from the first.
INPUT; STORE 10; INPUT; STORE 11; LOAD 10; SUB 11; OUT; HALT3
Countdown from 5
Counts down from 5 to 1 using a loop.
LOAD 10; OUT; SUB 11; STORE 10; IF ZERO 6; JUMP 1; HALT; 0; 0; 0; 5; 14
Double a Number
Takes an input and multiplies it by 2.
INPUT; STORE 10; ADD 10; OUT; HALT5
Multiply by 3
Takes an input and multiplies it by 3 using repeated addition.
INPUT; STORE 10; ADD 10; ADD 10; OUT; HALT6
Infinite Counter
Counts up from 0 indefinitely (Run at high speed).
LOAD 10; ADD 11; STORE 10; OUT; JUMP 1; 0; 0; 0; 0; 0; 0; 17
Logical Check (Is Zero?)
Outputs 1 (True) if input is 0, otherwise 0 (False).
INPUT; IF ZERO 4; LOAD 10; JUMP 5; LOAD 11; OUT; HALT; 0; 0; 0; 0; 18
Equality Checker
Inputs two numbers. Outputs 1 if they are equal, 0 if not.
INPUT; STORE 9; INPUT; SUB 9; IF ZERO 7; LOAD 10; JUMP 8; LOAD 11; OUT; 0; 0; 19
Swap Two Values
Swaps values in memory locations 10 and 11 using slot 9 as temp.
LOAD 10; STORE 9; LOAD 11; STORE 10; LOAD 9; STORE 11; HALT; 0; 0; 0; 5; 810
Input Accumulator
Keeps asking for input and adding it to a total until you enter 0.
LOAD 10; INPUT; IF ZERO 6; ADD 10; STORE 10; JUMP 1; LOAD 10; OUT; HALT; 0; 0Last modified: February 6th, 2026
