Syscall 2: Firmware, home

DriverChapter 11: Capstones

D44SENTENCE CHECK

The task

Deliver the body of each sentence whose XOR check matches; drop the rest.

The boat's instruments send sentences: a dollar sign ($24), a body such as DPT,12.4, an asterisk ($2A), two hex digits, and $0D $0A. The digits are the XOR of every character of the body.

For each sentence whose check matches, deliver the body to the host, then $0A. Deliver nothing for a sentence whose check does not match. The hex digits are '0' to '9' and 'A' to 'F'.

Noise between sentences never holds a dollar sign. A body holds 1 to 24 characters and never a dollar sign or an asterisk, and this card has 28 cells of RAM.

The board

The line card of SENTENCE CHECKThe line card: registers A B C D, 36 lines of ROM, 28 cells of RAM, a 16 byte receive buffer, a stack 4 deep. It talks to the line and to a host.LINETHE FAR ENDRXTXCARDREGISTERSA B C DROM36 LINESRAM28 CELLSRX 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

Neither the dollar sign nor the asterisk is part of the XOR. The body cannot be delivered until the check has been read.

Hints

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

Hint 1Show

Throw bytes away until a dollar sign arrives. Then store the body in RAM and fold every character into D with XOR until the asterisk comes.

Hint 2Show

Turn the two digits into a byte as in Hex Loader: a routine that reads a digit and returns its value, the first shifted up by 4 and ORed with the second.

Hint 3Show

Compare the byte with D. Only when they match, deliver the stored body and $0A. The $0D $0A after the digits is noise for the next hunt.

Solution

Reveal the Full SolutionThe complete program for SENTENCE CHECK. 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.

HUNT:   IN A
        JNE A, '$', HUNT
        MOV B, 0
        MOV D, 0
BODY:   IN A
        JEQ A, '*', CHECK
        MOV [B], A
        ADD B, 1
        XOR D, A
        JMP BODY
CHECK:  CALL HEX
        SHL A, 4
        MOV C, A
        CALL HEX
        OR C, A
        JNE C, D, HUNT
        MOV C, 0
EMIT:   JEQ C, B, EOL
        MOV A, [C]
        HOUT A
        ADD C, 1
        JMP EMIT
EOL:    HOUT $0A
        JMP HUNT
HEX:    IN A
        SUB A, '0'
        JLT A, 10, DIG
        SUB A, 7
DIG:    RET
TICKS
867
at par
LINES
29
at par