What you learn today
- Repeat bitwise operations
- Combine packing and text
- Spot gaps
The last week of the year looks back. Three recaps sum up the expert level, each with an exercise that combines two topics. Today: bits and data.
The tools
| Instruction | does | trap |
|---|---|---|
and | tests and clears bits | works on integers, decimals are dropped |
or | sets bits | – |
xor | toggles bits | – |
not | flips all bits | not 0 is −1 |
sll/sla, srl, sra | shift | only sra keeps the sign |
rol, ror | rotate | within 54 bits, not 64 |
ext, ins | take a field, set a field | at most 53 bits long |
STR("…") | text into a number | at most 6 ASCII characters |
HASH("…") | name into a number | CRC32 as a signed 32-bit number |
Underneath there is always the same fact: a register is a decimal number with 53 bits of precision. Bit instructions turn it into an integer and back.
Combining packing and text
A status word like the ventilation's from day 345 is ideal for chips and unreadable for people. “35” tells you nothing. “SPUELN” does. The chip unpacks the word with ext and picks the matching text:
ext req wort 4 2 # bits 4-5: request
move text T_AUS
seq tmp req 1
select text tmp T_NORMAL text
sbn ANZ HASH("Lueftung") Mode TEXTMODUS
sbn ANZ HASH("Lueftung") Setting text # shows NORMAL instead of a number
The texts are defines with STR("…"). The preprocessor turns them into a number when loading, and a display in mode DisplayMode.String shows them as letters again.
Finding gaps
Go through the table and ask yourself for every line: can I work out an example in my head? and %1100 %1010, sra -32 3, ext %1011_0000 4 4 – if one of them sticks, read the day for it once more. The exam calculates exactly such examples.
No more than six characters fit into STR. “SPUELEN” has seven and does not load – that is why it says “SPUELN” here. Umlauts do not work at all.
Diagram
Exercise
Task
Show the status word “Lueft_Status” (format from day 345: bit 0 supply, bit 1 exhaust, bit 2 fault, bits 4–5 request) as plain text. The display “Lueftung” is in text mode and shows “AUS”, “NORMAL” or “SPUELN” – with the fault bit set, request 3 or a missing memory “FEHLER”. The display “Lueft_Pumpen” shows how many pumps are running, -1 without memory.
Hints
Hint 1
Missing memory: snan missing word, then select word missing 4 word – 4 is the fault bit.
Hint 2
Request with ext req word 4 2, the pumps with ext … 1 twice and add.
Hint 3
Text as a chain of seq and select, the fault bit last so it wins.
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