Member-only story
The Calcutron-33 Instruction-Set
Coverage of all the Calcutron-33 assembly instructions
If you want to program the Calcutron-33 CPU, my made up decimal number based RISC-like microprocessor, you need to know what instructions it supports and how they work. To get you started, let us look at a simple example of a Calcutron-33 program. It contains several instructions such as INP
, BGT
and JMP
. In addition, there are labels such as loop
, second
and first
. The latter are not instructions, but ways to refer to different locations in the program.
loop:
INP x1
INP x2
BGT x1, x2, first
second:
OUT x2
JMP loop
first:
OUT x1
JMP loop
HLT
This program keeps reading pairs of numbers from its input using the INP
instructions. The read numbers are stored in the x1 and x2 registers, respectively. Next, we compare the numbers in the x1 and x2 registers using the BGT
instruction. BGT
is shorthand for: "Branch if Greater Than." If the first operand x1 is greater than the second operand x2, the program jumps to the first
label. Here there is an instruction OUT x1
which writes the contents of the x1 register to output.
BGT
is what we call a conditional branch instruction. Conditional branch instructions evaluate a condition and if the condition is true, the microprocessor will jump to a…