Every arithmetic instruction follows the same pattern: target first, then the values.
add r1 r0 273.15 # r1 = r0 + 273.15
| Instruction | Meaning |
|---|---|
move r? a | r = a |
add r? a b | r = a + b |
sub r? a b | r = a − b |
mul r? a b | r = a · b |
div r? a b | r = a / b |
mod r? a b | remainder of a / b (never negative for positive b) |
a and b may be a register or a fixed number. The target must always be a register. You may write into the same register you read from: add r0 r0 1 counts r0 up by one.
Kelvin, not Celsius
Stationeers measures temperatures in Kelvin. 0 °C is 273.15 K. Every gas sensor reports Kelvin, every heater expects Kelvin.
# r0 comes from the sensor in Kelvin
sub r1 r0 273.15 # r1 = degrees Celsius for the display
In the IC10 coder you can type 21C and press space – the editor turns it into 294.15.
No brackets
There are no formulas like (a + b) * c. Split longer calculations into several lines and use a register as scratch space:
add r2 r0 r1 # intermediate result
mul r2 r2 0.5 # average of r0 and r1
Dividing by 0 does not crash, but returns “infinity”. Better check for that first.
Diagram
Exercise
Task
r0 holds a temperature in degrees Celsius (the test sets it beforehand). Convert it:
r1= the same temperature in Kelvinr2= the same temperature in Fahrenheit (°C · 1.8 + 32)
Hints
Hint 1
Kelvin: add r1 r0 273.15.
Hint 2
Fahrenheit needs two lines: multiply by 1.8 first, then add 32.
Hint 3
Do not overwrite r0 – you need it for both calculations.