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

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

Conditional calls: beqal, bltal & co.

beqal, bneal, bltal, bgtal, bleal and bgeal only call a subroutine if a comparison holds. Otherwise execution continues on the next line, and ra stays as it was.

Lesson 13 min Week 19

What you learn today

  • Beqal, bneal, bltal, bgtal, bleal, bgeal
  • Call only on a condition
  • Set ra correctly

The gas tank should vent on overpressure and refill on underpressure. Both jobs sit neatly in subroutines of their own. Instead of comparing first and then writing jal, it works in one line: call conditionally.

The family

The al instructions (and link) compare like the branches you know. If the comparison holds, they write the next line into ra like jal and jump:

Instructioncalls if
beqal a b targeta = b
bneal a b targeta ≠ b
bltal a b targeta < b
bgtal a b targeta > b
bleal a b targeta ≤ b
bgeal a b targeta ≥ b
bgtal press MAXPRESS toohigh    # only on overpressure
bltal press MINPRESS toolow     # only on underpressure

The subroutine ends with j ra as usual and returns behind the call.

Calling only on a condition

If it is not called, the chip simply continues on the next line. The subroutine then does nothing, not even reset anything. That is why a default state belongs before the calls:

move vent 0            # default state
move pump 0
bgtal press MAXPRESS toohigh
bltal press MINPRESS toolow
sbn VALVE HASH("Ablass") On vent

Every subroutine only sets what it is responsible for to 1. Writing happens after all calls, exactly once.

Setting ra correctly

ra only gets a new value when the call really happens. If nothing is called, ra still holds the value from last time. As long as every subroutine is only entered through its own call, that does no harm. It becomes dangerous when the chip runs into a subroutine: then its j ra jumps to an old place.

Warning

With NaN none of these instructions calls, except bneal: NaN is unequal to every number. A subroutine “on deviation” called with bneal is therefore called on sensor failure.

Tip

Subroutines belong after the j start of the main loop. Then the chip cannot run into them by accident.

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
If the condition holds, ra is set and the chip jumps. If not, it simply carries on.

Exercise

Task

Pipe analyzer “Tank”, digital valve “Ablass” (On = open), volume pump “Nachfuellung”, flashing light “Tankalarm”.

  • Above 5000 kPa: call the subroutine toohigh with bgtal – it opens the valve and sets the alarm.
  • Below 3000 kPa: call the subroutine toolow with bltal – it starts the pump.
  • Otherwise everything off. If the analyzer is missing: nothing runs, alarm on.

Hints

Hint 1

Before the calls: vent and pump to 0, alarm via snan from the pressure.

Hint 2

bgtal press MAXPRESS toohigh and bltal press MINPRESS toolow.

Hint 3

The subroutines only set their registers to 1 and end with j ra.

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