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
| Instruction | calls if |
|---|---|
beqzal a target | a = 0 |
bnezal a target | a ≠ 0 |
bltzal a target | a < 0 |
bgtzal a target | a > 0 |
blezal a target | a ≤ 0 |
bgezal a target | a ≥ 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.
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.
Show the error counter on a display. “2” tells a player at once that there are two sensors to look for.
Diagram
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
errorwithbnezal, 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
heatneedwithbltzal. - 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