Syscall 2: Firmware, home

DriverChapter 8: Scarcity

D28GAP METER

The task

Deliver each received byte after the ticks since the byte before it.

To track down a fault in a modem, the lab wants the timing of the line as well as its bytes.

For every received byte, deliver two bytes to the host: the number of ticks since the byte before it arrived, then the byte. For the first byte, deliver 0 in place of a count. Bytes are always 12 to 250 ticks apart.

This card has a clock. CLK reads the tick counter, which goes up by one every tick, so MOV B, CLK copies the time into B.

The board

The line card of GAP METERThe line card: registers A B C D, 16 lines of ROM, no RAM, a 16 byte receive buffer, a stack 8 deep, and CLOCK. It talks to the line and to a host.LINETHE FAR ENDRXTXCARDREGISTERSA B C DROM16 LINESRAMNONERX BUFFER16 BYTESSTACK8 DEEPUNITSCLOCKHOSTMESSAGES
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

Reading CLK before IN measures how long the card was busy, not when the byte came.

Hints

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

Hint 1Show

The card waits in IN, so it takes each byte on the tick it arrives. Read CLK straight after IN and keep it for the next byte.

Hint 2Show

The gap is this byte's time minus the last byte's time. Read CLK at the same point after every IN and the extra ticks cancel out.

Hint 3Show

First: IN A, MOV C, CLK, HOUT 0, HOUT A. LOOP: IN A, MOV B, CLK, MOV D, B, SUB B, C, MOV C, D, HOUT B, HOUT A, JMP LOOP.

Solution

Reveal the Full SolutionThe complete program for GAP METER. 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 C, CLK
        HOUT 0
        HOUT A
LOOP:   IN A
        MOV B, CLK
        MOV D, B
        SUB B, C
        MOV C, D
        HOUT B
        HOUT A
        JMP LOOP
TICKS
702
at par
LINES
12
at par