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

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

Relative with devices: brdse, brdns

brdse and brdns jump relatively depending on whether a device is on a pin. Short and clear for one or two fallback lines – too hard to follow for whole sections.

Lesson 13 min Week 16

What you learn today

  • Relative jump depending on a pin
  • Short fallback lines
  • Weigh readability

A sensor on a pin is optional: if it is attached, the chip should read it, otherwise take a fallback value. With bdns and a label that works. For one or two lines there is the shorter form: brdse and brdns.

Relative depending on the pin

Instructionjumps by n lines if
brdse device na device is set
brdns device nno device is set
move temp FALLBACK        # fallback value in case d1 is empty
brdns d1 2                # no device: leave out reading
l temp d1 Temperature

Without a device the chip jumps over the l, and temp keeps the fallback value. With a device it reads and overwrites it. Two lines, no label. As with bdse and bdns, a register holding a ReferenceId may serve as the device.

Short fallback lines

The pattern is called default first, exception after: first the safe value sits in the register, then comes the line that replaces it only under a condition.

Several optional sensors can be averaged like this. Every block only counts if its sensor is attached:

move total 0
move n 0
brdns d0 4
l t d0 Temperature
add total total t
add n n 1

The distance 4 skips the three lines after it.

Weighing readability

Relative branches save labels and lines. But they come at a price: whoever reads the code has to count lines, and every inserted line moves the targets. As a rule of thumb:

Stretchchoice
one to three linesrelative branch
whole sectionlabel with bdns
target in another sectionalways a label
Warning

brdns d1 2 jumps over one line, not two. The distance 1 would be the next line, so no jump at all. Whoever reads “2” as “skip two lines” lands one line too far.

Tip

Only divide by the count once it is greater than 0, or catch the result. Without any sensor total / n is 0 / 0 otherwise, and that gives NaN.

Diagram

Reading with l, writing with s Gas sensor (d0) Temperature 293.15 IC10 r0 = 293.15 Wall light (d1) On 1 l r0 d0 Temperature device → register s d1 On 1 value → device
If no device is attached, brdns skips the reading line. The fallback value before it then stays.

Exercise

Task

Gas sensors may be attached to d0 and d1, an LED display to d2. The wall heater “Labor” hangs on the network.

  • Use brdse/brdns to build the average of the attached sensors.
  • Heater on if the average is below 20 °C. Without a sensor: off.
  • The display shows the average in °C, −999 without a sensor. If the display is missing, there is no error.

Absolute comparison jumps and bdse/bdns are not allowed here.

Hints

Hint 1

One block per sensor: brdns sensorA 4, then read, add, count.

Hint 2

div mean total n gives NaN without a sensor – slt then leaves the heater off.

Hint 3

Display: brgtz n 2 skips move c NOVALUE, brdns display 2 skips the s.

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