What you learn today
- Replace pins with lbn/sbn
- move numbers into defines
- Keep the behaviour unchanged
In the lab there is a chip somebody wrote months ago. It works, but nobody dares to touch it. On top of that the lab is being rebuilt, and devices should be addressed by name instead of pins in future. Today you rebuild it – and the most important part is that afterwards it does exactly the same.
The old code
start:
yield
l r0 d0 Temperature
slt r1 r0 291.15
s d1 On r1
sgt r2 r0 297.15
s d2 On r2
sub r3 r0 273.15
s d3 Setting r3
j 1
What it does: below 18 °C the heater runs, above 24 °C the cooler, and the display shows the temperature in °C.
The new devices
| old | Device | Name on the network |
|---|---|---|
d0 | gas sensor | “Labor” |
d1 | wall heater | “Laborheizung” |
d2 | wall cooler | “Laborkuehler” |
d3 | LED display | “Labortemp” |
The device names stay German – they are names in the game.
How to go about it
- Add a header and sections.
- One define per device type with
HASH("prefab")and a comment. - The three numbers into defines: 291.15 K (18 °C), 297.15 K (24 °C), 273.15 as
CELSIUSOFFSET. - Every register gets an alias.
landswith pins becomelbnandsbnwithHASH("name"), batch modeAverage.j 1becomesj start.
Run the tests after every step. A rebuild that stays green along the way is a safe rebuild.
Milestones
- Cold: heater on.
- Warm: cooler on.
- The display shows °C.
- In the band between 18 and 24 °C: both off.
The checker shows you pins, bare registers and line jumps when you switch on the style hints in the “Checker” tab. Work through the list until it is empty.
Device names in ASCII only: “Laborkuehler”, not “Laborkühler”. With an umlaut the hash no longer matches the name you gave in the game.
Diagram
Project task
Task
Rebuild the lab chip in the workshop style without changing what it does:
- Devices through
lbn/sbnwith the names “Labor”, “Laborheizung”, “Laborkuehler”, “Labortemp” – no pins. - None of the numbers 291.15, 297.15, 273.15 in the body, everything in defines.
- An alias for every register, jump to a label.
Prefabs: StructureGasSensor, StructureWallHeater, StructureWallCooler, StructureConsoleLED5.
Milestones
- Milestone 1: cold – heater on
- Milestone 2: warm – cooler on
- Milestone 3: display in °C
- Milestone 4: in the band both off
Hints
Hint 1
Four prefab defines, three number defines – then the body is free of numbers.
Hint 2
l r0 d0 Temperature becomes lbn temp SENSOR HASH("Labor") Temperature Average.
Hint 3
s d1 On r1 becomes sbn HEATER HASH("Laborheizung") On heat.
Quiz
2 questions. You pass from 60 % – the server does the grading.
Complete the day
- Passed all milestones of the project
- 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