Syscall 2: Firmware, home

DriverChapter 6: Trees

D17BYTE ORDER

The task

Transmit each pair of host bytes in the opposite order.

The tide gauge keeps every reading as a 16-bit number with the low byte first. The harbor office's receiver reads the high byte first.

Each host message is a run of readings, two bytes each, low byte first. Transmit every reading high byte first. A message may be empty, and it never ends halfway through a reading.

The board

The line card of BYTE ORDERThe line card: registers A B, 8 lines of ROM, no RAM, a 16 byte receive buffer, a stack 8 deep. It talks to the line and to a host.LINENO PEERRXTXCARDREGISTERSA BROM8 LINESRAMNONERX BUFFER16 BYTESSTACK8 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

OUT sends the low byte of a register, as before. The end of a message can only come where a new reading would start, so the second HIN needs no check.

Hints

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

Hint 1Show

Read the low byte into A and the high byte into B, then transmit B before A.

Hint 2Show

Only the first byte of a reading can be the end of the message. When HIN gives -1 there, go back to the top for the next message.

Hint 3Show

TOP: HIN A, JEQ A, -1, TOP, HIN B, OUT B, OUT A. The card wraps back to top by itself.

Solution

Reveal the Full SolutionThe complete program for BYTE ORDER. 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:    HIN A
        JEQ A, -1, TOP
        HIN B
        OUT B
        OUT A
TICKS
87
at par
LINES
5
at par