D26DELTA
The task
Deliver the readings rebuilt from a start value and signed changes, high byte first.
To save air time, the barometer sends its first reading in full, as two bytes, high byte first. After that it sends only the change from the reading before, as one signed byte from -128 to 127.
Deliver every reading to the host as two bytes, high byte first: the first as it came, and each later one as the reading before plus the change. A signed byte above 127 stands for that value minus 256.
The board
Key idea
A negative number in 16 bits is 65536 minus its size, so adding it wraps around to the right answer.
Hints
Each hint goes a step further than the one before. Open them one at a time.
Hint 1Show
Rebuild the first reading in B from its two bytes: MOV BH, A for the first, MOV BL, A for the second.
Hint 2Show
A change above 127 is negative. SUB A, 256 turns it into the same negative number in 16 bits, and ADD B, A then counts down, borrowing from BH when it has to.
Hint 3Show
After the first reading: SEND: HOUT BH, HOUT BL, IN A, JLT A, 128, STEP, SUB A, 256. STEP: ADD B, A, JMP SEND.
Solution
Reveal the Full SolutionThe complete program for DELTA. 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.
IN A
MOV BH, A
IN A
MOV BL, A
SEND: HOUT BH
HOUT BL
IN A
JLT A, 128, STEP
SUB A, 256
STEP: ADD B, A
JMP SEND- TICKS
- 80
- at par
- LINES
- 11
- at par