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. Comparisons and select

Chapter 3 · Decisions & style

Comparisons and select

Deciding without jumps: sgt, slt & co. return 0 or 1, select picks one of two values.

Lesson 8 of 18 9 min

Jumps work, but they make programs messy quickly. Often there is a cleaner way: the result of a comparison is a number, and you can use it directly.

Set instructions: a comparison as a number

Instructionregister = 1 if
sgt r? a ba > b
sge r? a ba ≥ b
slt r? a ba < b
sle r? a ba ≤ b
seq r? a ba = b
sne r? a ba ≠ b

otherwise 0. Since On expects exactly 0 or 1, that fits perfectly:

l r0 d0 Temperature
sgt r1 r0 303.15   # 1 if warmer than 30 C
s d1 On r1         # light follows the comparison directly

select: the switch

select r? condition a b stores a in the register when the condition is non-zero, otherwise b.

select r2 r1 Color.Red Color.Green
s d2 Color r2

Color.Red and Color.Green are built-in names for colour numbers (red = 4, green = 2). An LED display’s colour is set through the LogicType Color.

And, or, not

With 0/1 values you can combine logically: and r3 r1 r2 is 1 when both are 1, or when at least one is 1. “Not” is easiest with seqz r4 r1 (1 becomes 0, 0 becomes 1).

Warning

and/or work bitwise. With pure 0/1 values that is exactly logical and/or – with other numbers you get surprises.

Diagram

Comparison and select as a switch temp = 313 sgt r1 temp 303 r1 = 1 select Color.Red Color.Green 4 if r1 ≠ 0 if r1 = 0
A comparison becomes 0 or 1. select uses that number as a switch: non-zero → first value, 0 → second value.

Exercise

Task

Like the last lesson, but without conditional jumps:

  • Warning light d1 on above 30 °C (303.15 K), otherwise off.
  • The LED display d2 shows the temperature in °C, red when it is too hot, otherwise green.

Only j start for the loop is allowed.

Hints

Hint 1

sgt r1 r0 303.15 puts 1 or 0 into r1 – exactly what On needs.

Hint 2

The colour: select r2 r1 Color.Red Color.Green, then s d2 Color r2.

Hint 3

The number on the display goes through Setting as before.

Esc
↑ ↓ selectEnter open/ opens search anywhere