stationeers.de Mod workshop · Dominik1199
DE Sign in
  1. Home
  2. IC10 academy
  3. Day 106

Day 106 of 365 · Advanced · Month 4: Network in detail

Relative branches: br and jr

Relative branches jump by a number of lines instead of to a label. Ideal for skipping a single line – and dangerous when you insert lines.

Lesson 14 min Week 16

What you learn today

  • Offset instead of label
  • Breq, brne, brlt, brgt, brle, brge, jr
  • Why labels are wrong there

So far every instruction jumps to a label. There is a second family: relative branches. They do not jump to a particular line but by a number of lines forward or back. That is handy for quickly skipping a single line.

Distance instead of label

The r in breq stands for relative. The last operand is not a target but a distance:

DistanceEffect
1next line, so no jump
2skip one line
3skip two lines
-1one line back
move heat 1
brlt temp TARGET 2    # cold: leave out the next line
move heat 0
sbn HEATER HASH("Labor") On heat

If it is cold, the chip jumps two lines ahead, that is over move heat 0. Otherwise it runs into that line and switches off.

The family

relativeabsolutejumps if
breq a b nbeqa = b
brne a b nbnea ≠ b
brlt a b nblta < b
brgt a b nbgta > b
brle a b nblea ≤ b
brge a b nbgea ≥ b
jr njalways

Why labels are wrong there

To the chip a label is just a number: the number of the line it sits on. If start: is on line 12 and you write jr start, the chip jumps 12 lines ahead, not to line 12. The program lands somewhere or past the end. There is no error when saving, but the checker in the IC10 coder reports it.

Warning

Every line counts towards the distance: comment lines, empty lines, label lines. If you insert a comment line between the jump and its target, the distance is no longer right. Relative branches therefore belong only over short stretches without comment lines in between.

Tip

Watch the direction with NaN. Every comparison with NaN is false, so brlt does not jump then. If move heat 1 comes first and switching off sits in the skipped line, the heater goes off when the sensor fails. Built the other way round, it would switch on.

Diagram

Flow with a conditional jump start: yield · l r0 r0 > 303.15? hot: On 1 On 0 yes: bgt jumps no: next line j start
The last operand is a distance: 1 is the next line, 2 skips one line, negative values go back.

Exercise

Task

Gas sensor “Labor”, wall heater “Labor”, LED display “Labortemp”. Use relative branches (breq, brne, brlt, brgt, brle, brge) for all decisions, no absolute comparison jumps. You may use j for the main loop.

  • Heater on below 20 °C, otherwise off. Off on sensor failure.
  • Display colour: below 18 °C Color.Blue, above 26 °C Color.Red, in between Color.Green. Color.Red on sensor failure.
  • The display shows the temperature in °C.

Hints

Hint 1

Heater: move heat 1, then brlt temp TARGET 2 and move heat 0.

Hint 2

Colour: green as default, then two checks with one skipped line each.

Hint 3

Check the NaN direction: brge and brle do not jump on NaN – both lines run, the last one sets red.

Quiz

4 questions. You pass from 60 % – the server does the grading.

Complete the day

  • Passed the simulator exercise
  • Passed the quiz with at least 60 %

Without an account progress is saved in this browser only.

Report a mistake in this lesson

Please sign in to report. Sign in

Esc
↑ ↓ selectEnter open/ opens search anywhere