What you learn today
- Connect batch and device checks
- Combine stack and subroutines
- Spot gaps
The advanced exam is getting closer. This week connects what you learned separately over the past months. Today: network and memory.
Connecting batch and device checks
| Tool | What for | Trap |
|---|---|---|
lbn … Average | value of devices with the same name | NaN without a match |
lbn … Maximum | largest value | −infinity without a match |
lb … Count | how many devices of the type | ignores the name |
lbns | a slot by name | an empty slot returns 0 |
bdnvl, bdnvs | can the device do this value? | only with a pin or ReferenceId |
Together they make a device check: Count says whether all devices are there, NaN says which name is missing.
Combining stack and subroutines
A subroutine measures a room whose name is in a register. lbn also takes the name from a register:
move name HASH("Raum1")
jal measure
If measure itself calls celsius, ra gets overwritten. So push ra at the start, pop ra before j ra. measure stores the readings as a table in the stack – but not at address 0:
add tmp i TABLE # TABLE = 100
poke tmp val
Spotting gaps
Can you say without looking it up …
- what
lbn … Maximumreturns without a match? (day 95) - why
Countwithlbnsays nothing about the name? (day 94) - in which order
puttakes its values? (day 123) - why a nested subroutine needs
push ra? (day 128) - when a relative jump tolerates a label? (never, day 106)
Wherever you hesitate, read that day again before the exam comes.
push, pop and poke share the same memory. If you put the table at address 0, the first poke overwrites exactly the place where push ra just put the return line. pop ra then fetches a reading, and j ra jumps into nowhere.
max with NaN gives NaN. Replace missing values with a clearly invalid value like −999 first – then the maximum stays usable.
Diagram
Exercise
Task
Three gas sensors “Raum1”, “Raum2”, “Raum3”. The main loop calls measure three times. Add the subroutines and the evaluation.
measure: read the temperature of the room inname, convert to °C withcelsius, store from stack address 100, count missing values, remember the warmest room- Display “Waermster” (°C, −999 if none), “Sensoren” (number of gas sensors), “Raum2” (value from the stack)
- Flashing light “Raumfehler” on when fewer than 3 sensors are there or a room is missing
Hints
Hint 1
measure calls celsius – so push ra at the start and pop ra before j ra.
Hint 2
Table: add tmp i TABLE, poke tmp val, then add i i 1.
Hint 3
Missing values: snan, add to missing, replace with NONE for max.
Hint 4
Count devices with lb tmp SENSOR Temperature Count, room 2 with get tmp db ROOM2.
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