D19HEX DUMP
The task
Transmit each received byte as two hex digits and a space.
The engineers watch the line on a teleprinter, which prints only characters. A byte such as $3C has to appear as the two characters 3 and C.
For every received byte, transmit the high nibble as a hex digit, then the low nibble, then a space ($20). The digits are '0' to '9' and the capitals 'A' to 'F'.
This card has a call stack. CALL DIGIT jumps to the label DIGIT and remembers where it came from, and RET goes back to the line after that CALL.
The board
Key idea
Keep the byte in B: each routine call works on A, and the low nibble still has to come out of the same byte.
Hints
Each hint goes a step further than the one before. Open them one at a time.
Hint 1Show
A nibble from 0 to 9 becomes '0' plus the nibble. A nibble from 10 to 15 becomes 'A' plus the nibble minus 10, which is '0' plus the nibble plus 7.
Hint 2Show
Write the conversion once, after the main loop, as a routine that transmits the digit for the nibble in A and ends with RET. Call it for each half of the byte.
Hint 3Show
TOP: IN B, MOV A, B, SHR A, 4, CALL DIGIT, MOV A, B, AND A, $0F, CALL DIGIT, OUT $20, JMP TOP. DIGIT: JLT A, 10, NUM, ADD A, 7. NUM: ADD A, '0', OUT A, RET.
Solution
Reveal the Full SolutionThe complete program for HEX DUMP. 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.
TOP: IN B
MOV A, B
SHR A, 4
CALL DIGIT
MOV A, B
AND A, $0F
CALL DIGIT
OUT $20
JMP TOP
DIGIT: JLT A, 10, NUM
ADD A, 7
NUM: ADD A, '0'
OUT A
RET- TICKS
- 173
- at par
- LINES
- 14
- at par