We are currently experiencing issues with email delivery; this is being resolved as quickly as possible.

stationeers.de Mod workshop · Dominik1199
DE Sign in
  1. Home
  2. IC10 academy
  3. Math: move, add, sub, mul, div

Chapter 1 · First steps

Math: move, add, sub, mul, div

The basic arithmetic instructions and why the chip thinks in Kelvin.

Lesson 3 of 18 8 min

Every arithmetic instruction follows the same pattern: target first, then the values.

add r1 r0 273.15   # r1 = r0 + 273.15
InstructionMeaning
move r? ar = a
add r? a br = a + b
sub r? a br = a − b
mul r? a br = a · b
div r? a br = a / b
mod r? a bremainder 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
Tip

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

Data flow of an arithmetic instruction add r1 r0 273.15 r0 = 21 273.15 + r1 = 294.15 the target always comes first
An arithmetic instruction reads two values, computes and stores the result in the target register on the left.

Exercise

Task

r0 holds a temperature in degrees Celsius (the test sets it beforehand). Convert it:

  • r1 = the same temperature in Kelvin
  • r2 = 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.

Esc
↑ ↓ selectEnter open/ opens search anywhere