Syscall 2: Firmware, home

DriverChapter 4: Stars and hubs

D5FIXED WIDTH

The task

Transmit each host message padded with spaces to 8 bytes.

The dispatch printer prints in fixed columns, and every field must take exactly eight characters. The host sends messages of at most eight characters.

Transmit each message, followed by enough spaces ($20) to make eight bytes in all. An empty message becomes eight spaces.

This card has a second register, B. DJN B, PAD subtracts 1 from B and jumps to PAD unless B reached zero.

The board

The line card of FIXED WIDTHThe line card: registers A B, 12 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 BROM12 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

Counting down from 8 as you send leaves the number of spaces still owed in B.

Hints

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

Hint 1Show

Keep a count in B. Start it at 8 and subtract 1 for every byte of the message you transmit.

Hint 2Show

At the end of the message, B holds the number of spaces still owed. Be careful when it is already zero: DJN would subtract first and wrap around.

Hint 3Show

START: MOV B, 8. Read and transmit with SUB B, 1 per byte. At -1, check JEQ B, 0, START before a loop of OUT $20 and DJN B, PAD.

Solution

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

START:  MOV B, 8
NEXT:   HIN A
        JEQ A, -1, PAD
        OUT A
        SUB B, 1
        JMP NEXT
PAD:    JEQ B, 0, START
        OUT $20
        DJN B, PAD
TICKS
124
at par
LINES
9
at par