Rabbit VM RFC
I would like to make a RISC architecture that is capable of comfortably sitting on top of nearly any other architecture. If it’s possible to compile to Rabbit, then a program can run on more or less any hardware or virtualized architecture.
Rabbit can be optimized per-architecture, while maintaining the same interface. It may, for example, take advantage of Intel’s SIMD behind the scenes.
space: A register or memory location.
Registers are 32 bits wide.
|Contains 0. MIPS style.|
|Flags used for comparison.|
|Sign flag. On if sign bit of result is on.|
|Zero flag. On if result is zero or numbers were the same.|
When it makes sense, the destination register is the first argument to an
instruction. The last argument to the following instructions may also be an
immediate value, denoted with a prefix of
|Stop the execution of the machine immediately.|
|Move one space into another.|
|Add two spaces into a third.|
|Subtract two spaces into a third. Sets flags.|
|Multiply two spaces into a third.|
|Divide two spaces into a third.|
|Shift right one space a number of times.|
|Shift left one space a number of times.|
|NAND two spaces.|
|XOR two spaces.|
|Branch if |
|Branch if |
|Read one character from |
|Print one character from a space to |
The last argument to the following macros may also be an immediate value,
denoted with a prefix of
There are two addressing modes:
(%reg). The former uses the value
in the register, and the latter uses the word at the address in the register.
instr %rA, %rB, %rC instr %rA, %rB instr %rA
+-----Immediate bit |+----Addressing mode bit C ||+---Addressing mode bit B |||+--Addressing mode bit A |||| +Dead space+ regB vvvv vvvvvvvvvvvv vvvv IIII MDDD 000000000000 CCCCBBBBAAAA ^^^^ ^^^^ ^^^^ Opcode regC regA VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Immediate value
Every bit in “Dead space” must be turned off. If one is turned on, the result is undefined.
If the immediate bit is on, then the instruction disregards
rC and instead
looks for its third argument in the 32 bits after the first instruction. For example:
1: 0001 1 000 000000000000 0001 0000 0000 2: 0000 0 000 000000000000 0000 0000 0111
move instruction with the immediate bit set. It will therefore
look for an immediate value in the following word (in this case, the value is
7), and then store it in
Addition works in a similar fashion:
1: 0010 1 000 000000000000 0001 0001 0000 2: 0000 0 000 000000000000 0000 0000 0001
add instruction with the immediate bit set. It looks for an
immediate value in the following word (in this case, 1), adds it to the value in
r1, then stores the result in
r1. So this instruction would be an increment
The addressing mode bits are simple; if a register’s addressing mode bit is on, then the address in the register is dereferenced when the instruction is being executed, and that data is used instead. For example:
1: 0010 0 100 000000000000 0111 0001 0000
Performs an addition operation that adds the contents of
stores the result in memory at the address in
Stages of compilation
The preprocessor will be responsible for macro expansion and label to address translation. Macros exist in the form of instruction expansions, done behind the scenes.
Floating point computation is left to the client (an exercise for the reader, if you will).
The memory layout is completely flat right now.