D38SOFT CRC
The task
Transmit each host message, then its CRC-8, computed without a CRC engine.
The alarm panels check every message with an 8-bit CRC. This card has no CRC engine, so the firmware has to do the engine's job one bit at a time.
Start the CRC at $00. For each byte of the message, XOR the byte into the CRC. Then, 8 times: shift the CRC left by 1, and if the bit shifted out was a 1, XOR the CRC with $07. Keep only 8 bits. After the message, transmit the CRC.
For example, the message $01 $02 $03 goes out as $01 $02 $03 $48.
The board
Key idea
This is what the CRC engine does inside for every byte, with a longer register and a different polynomial.
Hints
Each hint goes a step further than the one before. Open them one at a time.
Hint 1Show
Keep the CRC in B. In a 16-bit register, the bit shifted out of the low 8 bits lands in bit 8, which is $100.
Hint 2Show
After SHL B, 1: if B is $100 or more, XOR B with $107. That one XOR clears bit 8 and applies $07 at the same time.
Hint 3Show
NEXT: HIN A, JEQ A, -1, DONE, OUT A, XOR B, A, MOV C, 8. BIT: SHL B, 1, JLT B, $100, KEEP, XOR B, $107. KEEP: DJN C, BIT, JMP NEXT. DONE: OUT B, MOV B, 0.
Solution
Reveal the Full SolutionThe complete program for SOFT CRC. Open it only when you want the answer.
The reference program
The game's own solution to this ticket. It passes every test and scores exactly par on every benchmark.
NEXT: HIN A
JEQ A, -1, DONE
OUT A
XOR B, A
MOV C, 8
BIT: SHL B, 1
JLT B, $100, KEEP
XOR B, $107
KEEP: DJN C, BIT
JMP NEXT
DONE: OUT B
MOV B, 0- TICKS
- 451
- at par
- LINES
- 12
- at par