A register-based virtual machine and disassembler that is used by Kai's compile time execution.
All instructions are stored in 16 bits* with an immediate 0 to 8 bytes.
/----------------------------------------------------\
| Opcode Byte | Arguments | Immediate (0 - 8 bytes)† |
\----------------------------------------------------/
*: KaiVM's bytecode is little endian
†: An instruction has an immediate value when the opcode's most significant bit is set.
7 bit 0
---- ----
rrrB ALGZ
|||| ||||
|||| |||+- Zero: TODO
|||| ||+-- Greater: TODO
|||| |+--- Less: TODO
|||| +---- Above: TODO
|||+------ Below: TODO
+++------- Reserved: No effect
TODO
To ease debugging, KaiVM comes with a disassembler. You can build this target by running kai code/disassembler.kai
. To disassemble some bytecode, simply invoke the disassembler with a file.
Example:
$ ./disassembler examples/cmp.bc
ldi r1, 2h
cpy r2, r1
cmp r1, r2
jeq 0h
hlt