IC10 has no if and no loop instructions. Everything works through jumps to labels.
Labels
A label is a name with a colon, alone on its line:
hot:
It does nothing by itself, but marks the line as a jump target. If something follows it (hot: s d1 On 1), the chip does not understand the line.
Unconditional jump: j
j start always jumps. That is how you build the main loop.
Conditional jumps
| Instruction | jumps if |
|---|---|
beq a b target | a = b |
bne a b target | a ≠ b |
bgt a b target | a > b |
bge a b target | a ≥ b |
blt a b target | a < b |
ble a b target | a ≤ b |
beqz a target / bnez a target | a = 0 / a ≠ 0 |
If the condition is false, the chip simply continues with the next line.
start:
yield
l r0 d0 Temperature
bgt r0 303.15 hot # warmer than 30 C?
s d1 On 0 # no: light off
j start
hot:
s d1 On 1 # yes: light on
j start
Instructions starting with br (breq, brgt …) and jr jump relatively by a number of lines. A label is almost always wrong there, because its line number simply gets added. For labels always use the variants without r.
Never jump to line numbers like j 5. Insert a line above and the jump lands somewhere else. Labels move along.
Diagram
Exercise
Task
A warning light on d1 should be on when the sensor on d0 reads more than 30 °C (303.15 K) – otherwise off. Solve it with a conditional jump (bgt, blt …) inside an endless loop.
Hints
Hint 1
bgt r0 303.15 hot jumps to the label hot: when it is warmer.
Hint 2
Do not forget the j start after each branch – otherwise the chip falls through into the other branch.