Syscall 2: Firmware, home

DriverChapter 7: Frames and loops

D20HEX LOADER

The task

Deliver the bytes spelled by pairs of hex digits; skip spaces and line breaks.

Calibration tables reach the logger typed out in hex. Each byte is two digits, high nibble first, and the operator puts spaces and line breaks between bytes wherever they like.

Deliver each byte to the host. Skip every space ($20), $0D, and $0A; they never come between the two digits of one byte. The digits are '0' to '9' and the capitals 'A' to 'F'.

SHL A, 4 shifts A left by four bits, so its low nibble becomes the high nibble. OR A, B sets every bit of A that is set in B.

The board

The line card of HEX LOADERThe line card: registers A B, 16 lines of ROM, no RAM, a 16 byte receive buffer, a stack 4 deep. It talks to the line and to a host.LINETHE FAR ENDRXTXCARDREGISTERSA BROM16 LINESRAMNONERX BUFFER16 BYTESSTACK4 DEEPUNITSNONEHOSTMESSAGES
The line card this ticket gives you, with its registers, memory, buffers, and units. On a narrow screen, scroll the board sideways to see all of it.

Key idea

Every character the logger skips is below '0', so one compare throws them all away.

Hints

Each hint goes a step further than the one before. Open them one at a time.

Hint 1Show

Turn a digit into its value: subtract '0', and if the result is more than 9, subtract 7 more. Spaces and line breaks are all below '0'.

Hint 2Show

Read characters until one is a digit and convert it. Shift it up by 4 and keep it in B. Convert the next digit, OR B into it, and deliver the result.

Hint 3Show

GET: IN A, JLT A, '0', GET, SUB A, '0', JLT A, 10, DONE, SUB A, 7. DONE: RET. TOP: CALL GET, SHL A, 4, MOV B, A, CALL GET, OR A, B, HOUT A, JMP TOP.

Solution

Reveal the Full SolutionThe complete program for HEX LOADER. 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:    CALL GET
        SHL A, 4
        MOV B, A
        CALL GET
        OR A, B
        HOUT A
        JMP TOP
GET:    IN A
        JLT A, '0', GET
        SUB A, '0'
        JLT A, 10, DONE
        SUB A, 7
DONE:   RET
TICKS
215
at par
LINES
13
at par