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

Day 130 of 365 · Advanced · Month 5: Memory and structure

Conditional calls against zero

beqzal, bnezal, bltzal, bgtzal, blezal and bgezal call depending on how a value relates to zero. Ideal for jumping into error handling only when needed.

Lesson 13 min Week 19

What you learn today

  • Beqzal, bnezal, bltzal, bgtzal, blezal, bgezal
  • Error handling as a subroutine

Three zones, three sensors. If one fails, a warning lamp should come on and the display should say how many are missing. That error handling sits in a subroutine, and it is only called when something is really missing.

The family against zero

Instructioncalls if
beqzal a targeta = 0
bnezal a targeta ≠ 0
bltzal a targeta < 0
bgtzal a targeta > 0
blezal a targeta ≤ 0
bgezal a targeta ≥ 0

As with the branches against zero, you first build the deviation or a counter. Then one operand is enough.

sub dev t TARGET
bltzal dev heatneed       # too cold: request heating

Error handling as a subroutine

First you count the errors, then you call the handling once:

move missing 0
lbn t SENSOR HASH("Zone1") Temperature Average
snan tmp t
add missing missing tmp
# ... the same for Zone2 and Zone3
bnezal missing error      # only if something is missing

The subroutine error sets the fault message, and because it sits after the main loop it does not disturb the normal flow. If more kinds of errors are added later, they all end up in the same block.

Do not forget the default state

As yesterday: a subroutine that is not called resets nothing. That is why move fault 0 and move heat 0 come before the calls. Once the error is fixed, the lamp goes off by itself in the next pass.

Warning

bnezal calls on NaN, because NaN is not equal to zero. All other z calls do not on NaN. If you want to react to a failure, a counter of your own such as missing is therefore clearer than a bnezal directly on the reading.

Tip

Show the error counter on a display. “2” tells a player at once that there are two sensors to look for.

Diagram

Calling and returning from a subroutine Main loop 2 l r0 d0 Temperature 3 jal celsius 4 s d2 Setting r1 5 l r0 d1 Temperature 6 jal celsius 7 s d3 Setting r1 8 j start celsius: sub r1 r0 273.15 j ra ra = 4 back to line ra
Count the errors and only call the error handling if the counter is not zero.

Exercise

Task

Three gas sensors “Zone1” to “Zone3” (there are no other gas sensors on the network), wall heaters “Zonen”, flashing light “Stoerung”, LED “Fehlend”.

  • Count the missing sensors. If the number is not zero, call the subroutine error with bnezal, which sets the fault. The LED shows the number.
  • Build the average of all gas sensors minus 20 °C. If it is negative, call the subroutine heatneed with bltzal.
  • Default state before the calls: fault off, heater off.

Hints

Hint 1

Per zone: lbn, snan tmp t, add missing missing tmp.

Hint 2

Default state, then bnezal missing error.

Hint 3

Average of all gas sensors with lb … Temperature Average, minus TARGET, then bltzal dev heatneed.

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