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:
| Instruction | calls if |
|---|---|
beqal a b target | a = b |
bneal a b target | a ≠ b |
bltal a b target | a < b |
bgtal a b target | a > b |
bleal a b target | a ≤ b |
bgeal a b target | a ≥ 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.
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.
Subroutines belong after the j start of the main loop. Then the chip cannot run into them by accident.
Diagram
Exercise
Task
Pipe analyzer “Tank”, digital valve “Ablass” (On = open), volume pump “Nachfuellung”, flashing light “Tankalarm”.
- Above 5000 kPa: call the subroutine
toohighwithbgtal– it opens the valve and sets the alarm. - Below 3000 kPa: call the subroutine
toolowwithbltal– 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