Multiplication
c(0) = c(1) · c(2) by repeated addition
// Input: c(1), c(2) - Result: c(0)
// Only ADD and SUB - no MULT allowed!
1
CLOAD 0
2
STORE 3 // result := 0
3
LOAD 2 // loop: while c(2) > 0
4
IF c(0) = 0 GOTO 11
5
CSUB 1
6
STORE 2 // c(2) := c(2) - 1
7
LOAD 3
8
ADD 1
9
STORE 3 // result := result + c(1)
10
GOTO 3
11
LOAD 3
12
END
Counter b1Steps0Ready
Next instruction
CLOAD 0Registers
Set the input values, then runc(0)
c(1)
c(2)
c(3)
c(4)
c(5)
c(6)
c(7)
c(8)
c(9)
Last steps
Nothing executed yet. Press Step or Run.
Halted0
Steps0in total
Correct0
Run a program to the end; finished runs are counted here.
Instruction set
One instruction per line, numbered from 1. // starts a comment. Registers hold natural numbers, so subtraction never drops below 0.
LOAD ic(0) := c(i)CLOAD ic(0) := iINDLOAD ic(0) := c(c(i))STORE ic(i) := c(0)INDSTORE ic(c(i)) := c(0)ADD ic(0) := c(0) + c(i)CADD ic(0) := c(0) + iINDADD ic(0) := c(0) + c(c(i))SUB ic(0) := max(0, c(0) − c(i))CSUB ic(0) := max(0, c(0) − i)INDSUB ic(0) := max(0, c(0) − c(c(i)))MULT ic(0) := c(0) · c(i)CMULT ic(0) := c(0) · iINDMULT ic(0) := c(0) · c(c(i))DIV ic(0) := ⌊c(0) / c(i)⌋CDIV ic(0) := ⌊c(0) / i⌋INDDIV ic(0) := ⌊c(0) / c(c(i))⌋GOTO jb := jIF c(0) ? x GOTO j- Jump to j if the comparison holds, else go on with b + 1. Comparisons: =, <, <=, >, >=
END- Halt
About this tool
Accumulator c(0)
Every calculation runs through register c(0). LOAD fetches a value, STORE writes it back to any register c(i).
Three ways to address
ADD 3 adds register c(3), CADD 3 adds the constant 3, INDADD 3 adds the register whose number is stored in c(3).
Turing-complete
With just these few instructions a register machine can compute everything a Turing machine can, and it is much closer to a real CPU.
Learn more
Keyboard
- Space
- Run or pause
- ←→
- Step back or forward
- E
- Run to the end
- R
- Reset the machine