What you learn today
- What exactly counts
- Preprocessor and long form
- Measure characters
You have known the limits since day 5: 128 lines, 90 characters per line, 4096 characters in total. For small chips they do not matter. With the big plants of the last weeks you run into them – and then every detail of what exactly counts matters.
What exactly counts
| Limit | counts |
|---|---|
| 128 lines | every line: code, comment, blank line, label, define, alias |
| 90 characters per line | everything in the line, including the comment after it |
| 4096 characters | the whole text, including spaces, comments and line breaks |
A line that has 95 characters with its comment is too long – even if the code alone only has 60. The chip then cannot be loaded.
Preprocessor and long form
The preprocessor replaces HASH("…"), STR("…"), %1010 and $FF with numbers when loading. But the counting happens before that, in the long form, as you wrote it:
| written | characters | after the preprocessor |
|---|---|---|
HASH("StructureHydroponicsTrayData") | 37 | -1841632400 |
HASH("Beet") | 12 | a number |
%1111_1111 | 10 | 255 |
A define therefore pays off from the second use: the line define TRAY HASH("StructureHydroponicsTrayData") costs about 50 characters once, every use after that saves 33.
lbns ripe HASH("StructureHydroponicsTrayData") HASH("Beet") 0 Mature Average
define TRAY HASH("StructureHydroponicsTrayData") # hydroponics device
lbns ripe TRAY HASH("Beet") 0 Mature Average
Measuring characters
The IC10 coder on this site shows lines and characters while you write and marks every line over 90 characters. In the game you only see it when the chip rejects the code. You can estimate like this:
- A typical instruction line has 25 to 45 characters.
- 128 lines of 32 characters each are already 4096 – with long comments you almost always reach the character limit before the line limit.
Every line counts with a line break. 100 blank lines are 100 characters and 100 of 128 lines – gaps between sections are not free.
Rather write comments above the line than after it. Then the instruction line stays short, and a long explanation does not blow the 90 characters.
Diagram
Exercise
Task
The starter code works but cannot be loaded: three lines are longer than 90 characters. Bring every line below 90 characters by moving the prefab hashes into defines and putting long comments above the line. The behaviour stays the same.
Hints
Hint 1
Create define TRAY HASH("StructureHydroponicsTrayData") and define DISP HASH("StructureConsoleLED5").
Hint 2
In the body use TRAY and DISP instead of the long HASH calls.
Hint 3
Move the comments behind the instructions one line up.
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