What you learn today
- Sections with # --- 1. ---
- Kelvin literal with Celsius comment
- CELSIUSOFFSET
- Labels instead of line numbers
From today on all programs in the course look the same. That is not an end in itself: whoever opens a chip in the base should find within five seconds where the target is and which register holds what. Dominik has built his chips like this for years, and in this course you will read hundreds more programs in this style.
Sections
A program has a header and numbered sections:
# --- Frost guard storage ---
# --- 1. Settings ---
define LIMIT 278.15 # 5 C
# --- 2. Registers and devices ---
alias temp r0
alias cold r1
# --- 3. Main loop ---
start:
yield
Further sections inside the loop get the next number: # --- 4. Heater ---, # --- 5. Display ---. Short and in ASCII, comments count towards the character limit.
Kelvin value with a Celsius comment
The chip computes in Kelvin, people think in Celsius. That is why the value sits in Kelvin in the define and the Celsius behind it in the comment:
define TARGET 294.15 # 21 C
define ALARM 313.15 # 40 C
Or: CELSIUSOFFSET
If you want to set targets directly in Celsius, store the offset as a define and convert once before the main loop:
define CELSIUSOFFSET 273.15 # 0 C in Kelvin
define TARGET_C 21 # target in C
alias target r1
add target TARGET_C CELSIUSOFFSET
A define must not compute with another define. define TARGET TARGET_C or a define pointing at CELSIUSOFFSET gives NaN, without an error message. A define's value is only a number, a constant, a Namespace.Name or HASH("…"). That is why the conversion goes through a register with add.
Labels instead of line numbers
A jump to a line number works – until someone inserts a line above it. Then the chip jumps one line off, and nobody notices right away:
j 9 # points at yield today, at something else tomorrow
A label moves along. That is why every program in the course only jumps to labels.
The rules at a glance
| Rule | Example |
|---|---|
| every fixed value as a define with a comment | define LIMIT 278.15 # 5 C |
| every register with an alias, right after the defines | alias temp r0 |
| numbered sections | # --- 3. Main loop --- |
| main loop with yield and a jump back | start: … j start |
| only labels as jump targets | j start instead of j 9 |
The checker in the IC10 coder can show style hints based on these rules. Switch them on in the “Checker” tab and you see bare registers and line jumps right away.
Diagram
Exercise
Task
The starter code works but is written in the old style. Bring it into the workshop style without changing what it does:
- Header and numbered sections.
- The limit of 19 °C not as a raw number in the body: either a
definein Kelvin with a Celsius comment orCELSIUSOFFSETwithadd. - Every register in use gets an
alias. - No jump to a line number.
Hints
Hint 1
Header: # --- Frost guard storage ---, then # --- 1. Settings ---.
Hint 2
define CELSIUSOFFSET 273.15 and define LIMIT_C 19, then before the loop add limit LIMIT_C CELSIUSOFFSET.
Hint 3
j 1 becomes j start.
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