Instruction set
The Chombit CPU has only 25 instructions to learn. It's hard to believe, but everything your program does is accomplished by some combination of just these instructions.
Register and memory transfer
- MOVE: Set the left register to the value of the right operand (register or literal value).
- CONVERT: Set the left register to the value of the right register with a different size.
- LOAD: Read a value from a memory location into a framed register.
- STORE: Write a constant value or framed register to a memory location.
Stack operations
- PUSH: Push a value onto the top of the SP stack.
- POP: Pop the top value from the SP stack and assign it to the specified register.
- GPUSH: Push a garbage collector root onto the GP stack.
- GPOP: Pop one or more garbage collector roots from the GP stack.
Arithmetic
- ADD: Add the two operands and store their sum in the left operand.
- SUBTRACT: Subtract the right operand from the left operand, storing the difference in the left operand.
- COMPARE: Compare the two operands and set the flags.
- MULTIPLY: Multiply the two operands and store the product in the left operand.
- DIVIDE: Divide the left operand by the right operand to calculate a quotient and optional remainder.
- NEGATE: Multiply the operand by -1.
- WITH: Enable a special behavior for the subsequent instruction.
Bit operations
- AND: Compute the bitwise AND of the two operands, storing the result in the left operand.
- OR: Compute the bitwise OR of the two operands, storing the result in the left operand.
- XOR: Compute the bitwise exclusive OR of the two operands, storing the result in the left operand.
- SHIFT: Perform a logical or arithmetic shift of the operand's value.
Control flow
- IF: Skip over the next instruction unless a condition is true according to the CPU flags.
- JUMP: Move the instruction pointer (
IP) to an arbitrary location. - SLEEP: Temporarily put the CPU to sleep to save electrical power.
Debugging tools