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

Day 18 of 365 · Beginner · Month 1: First steps

Branching against zero

bltz, bgtz, blez and bgez jump depending on the sign. With a difference instead of two values every decision becomes: above or below zero?

Lesson 10 min Week 3

What you learn today

  • Use bltz, bgtz, blez, bgez
  • Compare differences instead of two values
  • Read signs

In the airlock it does not matter how high the pressure is, but how far apart chamber and outside are. Questions like that are best answered with a difference and a jump against zero.

The four new jumps

Instructionjumps if
bltz a targeta < 0
bgtz a targeta > 0
blez a targeta ≤ 0
bgez a targeta ≥ 0

Together with beqz and bnez from the last lesson you now have all six comparisons against zero. The z stands for zero.

Difference first, jump second

start:
yield
l r0 d0 Pressure     # chamber
l r1 d1 Pressure     # outside
sub r2 r0 r1         # chamber minus outside
bgtz r2 higher       # chamber has more pressure
s d2 On 0
j start
higher:
s d2 On 1
j start

The sign of r2 carries all the information: positive means more pressure in the chamber. You can put the difference straight on a display – “+12” says more than two separate pressures.

Reading signs

Differencemeans
actual − target < 0too little: too cold, too low, too empty
actual − target > 0too much: too warm, too high, too full
actual − target = 0hit exactly – almost never with readings

Adding a band

If you only want to react from a 5 kPa difference, shift the difference before the jump:

sub r3 r2 5          # only positive above +5
bgtz r3 toohigh
add r3 r2 5          # only negative below -5
bltz r3 toolow
Warning

Do not forget the j start after each branch. Without the jump the chip simply falls into the next branch and switches everything again there.

Tip

bgtz and bgez only differ at exactly 0. With readings that is rare – with counters it is common. With counters always think about what should happen at exactly zero.

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
A conditional jump splits the flow: if the condition holds, execution continues at the label, otherwise on the next line.

Exercise

Task

An airlock indicator: d0 measures the chamber, d1 the outside. d3 is an LED display, d2 the release light.

  • The display always shows chamber − outside in kPa.
  • More than 5 kPa too high: light off, display orange (3).
  • More than 5 kPa too low: light off, display blue (0).
  • Otherwise: light on, display green (2).

Solve it with bgtz/bltz (or bgez/blez).

Hints

Hint 1

sub r3 r2 5 only turns positive when the chamber is more than 5 kPa above outside.

Hint 2

add r3 r2 5 only turns negative when it is more than 5 kPa below.

Hint 3

Every branch ends with j start.

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