Programmable combinators
Version 0.3.0 includes basic error handling so should be much more stable.
Instruction set
These combinators come with 32 general purpose registers (x0 - x31) and 4 special-purpose output registers (o0-o3). The register x0 is special, it always contains 0, x1 to x31 can contain any number. Only interact with the output registers using the special-purpose instruction WSIG.
Instructions
Currently implemented instructions:
Instruction | Explanation | Example |
---|---|---|
HLT | Sets the halt flag. Combinator won't continue executing after halting | HLT |
NOP | No operation. Consumes an execution cycle without doing anything | NOP |
ADDI rd, r1, imm | Destination register rd = r1 + imm | ADDI x1, x0, 10 |
SUB rd, r1, r2 | rd = r1 - r2 | SUB x2, x0, x1 |
SLT rd, r1, r2 | Set less than: rd = 1 if r1 < r2, otherwise rd = 0 | SLT x4, x1, x2 |
SLTI rd, r1, imm | Set less than immediate: rd = 1 if r1 < imm, otherwise rd = 0 | SLTI x4, x1, 5 |
WSIG rd, r1, r2 | Write signal type r1 with amount in r2 to output register | WSIG o1, copper-plate, x1 |
JAL rd, label | Jump to label, save current program counter to rd | JAL x0, main |
BEQ r1, r2, label | Branch if equal: if r1 == r2, then PC = label | BEQ x1, x2, end |
BNE r1, r2, label | Branch if not equal: if r1 != r2, then PC = label | BNE x1, x0, loop |
Registers
Here are the actual RISC-V register names:
Register | ABI Name | Description |
---|---|---|
x0 | zero | hardwired zero |
x1 | ra | return address |
x2 | sp | stack pointer |
x3 | gp | global pointer |
x4 | tp | thread pointer |
x5 | t0 | temporary register 0 |
x6 | t1 | temporary register 1 |
x7 | t2 | temporary register 2 |
x8 | s0 / fp | saved register 0 / frame pointer |
x9 | s1 | saved register 1 |
x10 | a0 | function argument 0 / return value 0 |
x11 | a1 | function argument 1 / return value 1 |
x12 | a2 | function argument 2 |
x13 | a3 | function argument 3 |
x14 | a4 | function argument 4 |
x15 | a5 | function argument 5 |
x16 | a6 | function argument 6 |
x17 | a7 | function argument 7 |
x18 | s2 | saved register 2 |
x19 | s3 | saved register 3 |
x20 | s4 | saved register 4 |
x21 | s5 | saved register 5 |
x22 | s6 | saved register 6 |
x23 | s7 | saved register 7 |
x24 | s8 | saved register 8 |
x25 | s9 | saved register 9 |
x26 | s10 | saved register 10 |
x27 | s11 | saved register 11 |
x28 | t3 | temporary register 3 |
x29 | t4 | temporary register 4 |
x30 | t5 | temporary register 5 |
x31 | t6 | temporary register 6 |
With a guide on how they should be used. The ABI Names are not implemented in this mod yet.
Example programs
main:
ADDI x10, x0, 0
loop:
ADDI x10, x10, 1
WSIG o1, copper-plate, x10
WAIT 6
SLTI x6, x10, 100
BNE x6, x0, loop
JAL x1, main
A counter from 0 to 100, outputs the result as copper plates to the circuit network. Waits 6 game ticks between updates.