Syscall 2: Firmware, home

DriverChapter 7: Frames and loops

D24WORD SUM

The task

Transmit the 16-bit sum of each host message's readings, high byte first.

Each pipeline meter reports a batch of 16-bit flow readings, high byte first. The control room only wants the total of each batch.

For each host message, transmit the sum of its readings as 16 bits, high byte first, keeping only the low 16 bits. A message holds 0 to 6 readings, so an empty one sends $00 $00.

AH and AL name the high and low bytes of A. MOV AH, B writes only the high byte and leaves AL alone. B, C, and D have halves too.

The board

The line card of WORD SUMThe line card: registers A B C, 14 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 B CROM14 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

Adding whole 16-bit readings carries from the low byte into the high byte by itself.

Hints

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

Hint 1Show

Read each byte into a full register first. HIN gives -1 as 16 bits, and a byte register would hold $FF, which is also a byte a reading can contain.

Hint 2Show

MOV AH, B puts the first byte of a reading in the high half of A, and MOV AL, B the second in the low half. Then ADD C, A adds the whole reading at once.

Hint 3Show

START: MOV C, 0. NEXT: HIN B, JEQ B, -1, SEND, MOV AH, B, HIN B, MOV AL, B, ADD C, A, JMP NEXT. SEND: OUT CH, OUT CL.

Solution

Reveal the Full SolutionThe complete program for WORD SUM. 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 C, 0
NEXT:   HIN B
        JEQ B, -1, SEND
        MOV AH, B
        HIN B
        MOV AL, B
        ADD C, A
        JMP NEXT
SEND:   OUT CH
        OUT CL
TICKS
90
at par
LINES
10
at par