Syscall 2: Firmware, home

SignalChapter 10: Meshes

78KNOCKOUT

The task

P must receive the largest of X, Y, and Z each time, and Q the smallest.

a is an SC-2L, a low power core: 2 cycles an instruction, at half the energy.

b is an SC-1, a lite core: register A only. hi and lo are standard cores.

The board

The board of KNOCKOUT4 cores: a, b, hi, and lo. Inputs X, Y, and Z; outputs P and Q.aSC-2L 15 LINESbSC-1 4 LINEShiSC-2 15 LINESloSC-2 15 LINESP0P1P2P3P0P1P2P0P1P2P0P1P2XYZPQ
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

One comparison gives two results: the larger value plays on for P and the smaller for Q.

Hints

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

Hint 1Show

One comparison gives two results: the larger value plays on for P, the smaller for Q.

Hint 2Show

a puts X and Y in order and sends one to hi and one to lo. b sends Z to both.

Hint 3Show

SUB B leaves the second value minus the first. Add B back to get the second value again.

Solution

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

aSC-2L low power

IN P0
MOV B, A
IN P1
SUB B
JL K
ADD B
JMP T
K: ADD B
XCH A, B
T: OUT P2
XCH A, B
OUT P3

bSC-1 lite

IN P0
OUT P1
OUT P2

hiSC-2 standard

IN P0
MOV B, A
IN P1
SUB B
JG K
MOV A, 0
K: ADD B
OUT P2

loSC-2 standard

IN P0
MOV B, A
IN P1
SUB B
JL K
MOV A, 0
K: ADD B
OUT P2
CYCLES
866
at par
ENERGY
5115
at par
NODES
4
at par
INSTRUCTIONS
31
at par

Another way: Compare late

A second program that also passes. It beats par on CYCLES and gives some back on ENERGY and INSTRUCTIONS.

A only passes X and Y on, and hi and lo each compare all three values: faster, since the comparisons move to the 1 cycle cores, but they cost 2 energy each.

aSC-2L low power

IN P0
OUT P2
OUT P3
IN P1
OUT P2
OUT P3

bSC-1 lite

IN P0
OUT P1
OUT P2

hiSC-2 standard

IN P0
MOV B, A
IN P0
SUB B
JL K
ADD B
MOV B, A
K: IN P1
SUB B
JG M
MOV A, 0
M: ADD B
OUT P2

loSC-2 standard

IN P0
MOV B, A
IN P0
SUB B
JG K
ADD B
MOV B, A
K: IN P1
SUB B
JL M
MOV A, 0
M: ADD B
OUT P2
CYCLES
777
under par
ENERGY
6535
over par
NODES
4
at par
INSTRUCTIONS
35
over par