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
| Instruction | jumps if |
|---|---|
bltz a target | a < 0 |
bgtz a target | a > 0 |
blez a target | a ≤ 0 |
bgez a target | a ≥ 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
| Difference | means |
|---|---|
actual − target < 0 | too little: too cold, too low, too empty |
actual − target > 0 | too much: too warm, too high, too full |
actual − target = 0 | hit 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
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.
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
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