Syscall 2: Firmware, home

SignalChapter 8: Scarcity

60HEADROOM

The task

P must receive each X value held between -20 and 60: lower values become -20, higher ones 60.

c is an SC-1, with register A only and 8 lines. h is a standard core.

The board

The board of HEADROOM2 cores: c and h. Inputs X; outputs P.cSC-1 8 LINEShSC-2 15 LINESP0P1P0P1XP
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

The stop at 999 does the work of a jump: ADD then SUB one constant holds one side.

Hints

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

Hint 1Show

h has room for the jumps that hold each side; c is an SC-1 with only 8 lines.

Hint 2Show

SUB 60, then clear a positive gap, then ADD 80 and clear a negative gap, then SUB 20.

Hint 3Show

Two jumps for each side need 9 lines, one more than c holds.

Solution

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

cSC-1 lite

IN P0
OUT P1

hSC-2 standard

IN P0
SUB 60
JL L
MOV A, 0
L: ADD 80
JG G
MOV A, 0
G: SUB 20
OUT P1
CYCLES
334
at par
ENERGY
1976
at par
NODES
2
at par
INSTRUCTIONS
11
at par

Another way: Jumps on h

A second program that also passes, and matches par on every benchmark.

Same clamp on h, with c saving a cycle by NOP-free pass.

cSC-1 lite

IN P0
OUT P1

hSC-2 standard

IN P0
SUB 60
JL L
MOV A, 0
L: ADD 80
JG G
MOV A, 0
G: SUB 20
OUT P1
CYCLES
334
at par
ENERGY
1976
at par
NODES
2
at par
INSTRUCTIONS
11
at par

Another way: Split

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

C holds the top and h the bottom.

cSC-1 lite

IN P0
SUB 60
JL L
MOV A, 0
L: ADD 60
OUT P1

hSC-2 standard

IN P0
ADD 20
JG G
MOV A, 0
G: SUB 20
OUT P1
CYCLES
259
under par
ENERGY
1855
under par
NODES
2
at par
INSTRUCTIONS
12
over par