Syscall 2: Firmware, home

SignalChapter 9: Special nodes

67QUEUE

The task

Each X value that is not 0 joins the back of a queue. Each 0 takes the oldest out for P.

A 0 on an empty queue sends 0. The queue never holds more than three values.

fifo is an SC-4: registers A, B, C, and D, and 3 energy an instruction.

The board

The board of QUEUE1 core: fifo. Inputs X; outputs P.fifoSC-4 15 LINESP0P1XP
The board as the puzzle screen lays it out. Cyan pins read, lemon pins write, violet pins go both ways. On a narrow screen, scroll the board sideways to see all of it.

Key idea

A 0 in a register is an empty place, so a pop takes the deepest value that is not 0 and empties it in the same swap.

Hints

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

Hint 1Show

No value in the queue is 0, so a register that holds 0 is an empty place.

Hint 2Show

Push at B as the stack did. Then the oldest value is the deepest one that is not 0.

Hint 3Show

With a 0 in A, XCH A, D takes D out and leaves it empty. JNZ tells you whether it held one.

Solution

Reveal the Full SolutionThe complete program for QUEUE. Open it only when you want the answer.

The reference program

The game's own solution. It passes every test and scores exactly par on every benchmark.

fifoSC-4 quad

S: IN P0
JZ O
XCH A, B
XCH A, C
XCH A, D
JMP S
O: XCH A, D
JNZ F
XCH A, C
JNZ F
XCH A, B
F: OUT P1
CYCLES
226
at par
ENERGY
1806
at par
NODES
1
at par
INSTRUCTIONS
12
at par