sgt r1 r0 303.15 – what was r1 again? And why 303.15? In three weeks nobody knows. Two instructions bring order.
define: names for fixed numbers
define LIMIT 303.15 # 30 C
Wherever LIMIT appears afterwards, the chip uses 303.15. A define costs no register and never changes. Perfect for set points, thresholds and later for device types.
alias: names for registers and pins
alias temp r0
alias sensor d0
Now you may write temp instead of r0 and sensor instead of d0. An alias on a pin also shows up at the housing’s screws.
The layout that works
# --- Heat warning ---
# --- 1. Settings ---
define LIMIT 303.15 # 30 C
# --- 2. Registers and devices ---
alias sensor d0
alias light d1
alias temp r0
alias hot r1
# --- 3. Main loop ---
start:
yield
l temp sensor Temperature
sgt hot temp LIMIT
s light On hot
j start
First define, then alias, then the main loop with yield. Every number you might want to tune later sits at the top with a comment – the body only contains names.
Comments count fully towards the 4096-character limit. Short, precise comments beat long prose. If it gets tight, the “game version” in the IC10 coder helps.
A define value may be a number, a constant or HASH("…") – but not another define name. The game silently stores NaN then.
Diagram
Exercise
Task
The code below works, but is barely readable. Restructure it without changing what it does:
- The limit 303.15 gets a
definewith a comment. - Every register in use gets an
alias. - The body contains no raw 303.15 and no bare
r0/r1any more.
Hints
Hint 1
define LIMIT 303.15 # 30 C at the very top.
Hint 2
Then alias temp r0 and alias hot r1 – and replace r0 with temp and r1 with hot in the body.
Hint 3
The pins may get an alias too: alias sensor d0.