Syscall 2: Firmware, home

ShuffleChapter 11: Capstones

S45TOP SHELF

The task

Peak hold, with every piece of the program out of place.

While the clock on P1 is low, keep the highest reading of P0.

At each rising edge, write that peak to P2 and start over.

The board

The chip of TOP SHELFChip u1 with 3 ports: P0 analog in, reaching V2, CH1; P1 digital in, reaching V3, CH2; P2 pwm out, reaching R1, C1, CH3.u1CHIP SC-2P0ANALOG INV2, CH1P1DIGITAL INV3, CH2P2PWM OUTR1, C1, CH3
The chip's ports, each with its kind and the parts its signal reaches. Cyan reads, lemon writes. On a narrow screen, scroll the board sideways to see all of it.
Sources
V1 2.5 V, V2 2 V sine at 25 Hz, and V3 5 V square at 125 Hz
Resistors
R1 1 kΩ
Capacitors
C1 1 µF
Probes
CH1, CH2, and CH3

Key idea

Par is 8 swaps. Core u1 needs 3 instruction swaps and 5 operand swaps. 4 of them trade two tiles that hold each other's places; look for those first, since one swap mends both.

Hints

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

Hint 1Show

SUB B compares a reading with the peak in B, and ADD B gives the reading back.

Hint 2Show

A reading under the peak skips straight to the clock check.

Hint 3Show

After the write, clear B and wait for the clock to fall.

Solution

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

The board as dealt

This is the arrangement the game deals. Framed tiles are the ones out of place.

u1SC-2 standard

L: IN B
SUB B
JZ K
ADD A
MOV B, A
K: IN P0
OUT H
MOV B, B
IN P2
MOV A, 0
MOV P1, A
H: JL L
JNZ P1

8 swaps back

Make these swaps in order. Lines are numbered from 1 in each core.

  1. In core u1, swap the operand A on line 4 with B on line 8.
  2. In core u1, swap the operand B on line 1 with P0 on line 6.
  3. In core u1, swap the operand B on line 6 with P1 on line 11.
  4. In core u1, swap the operand H on line 7 with L on line 12.
  5. In core u1, swap the operand H on line 12 with P1 on line 13.
  6. In core u1, swap the instruction JZ on line 3 with JL on line 12.
  7. In core u1, swap the instruction OUT on line 7 with JZ on line 12.
  8. In core u1, swap the instruction IN on line 9 with OUT on line 12.

The finished program

Every tile back in place: the reference solution, which scores exactly par on every benchmark.

u1SC-2 standard

L: IN P0
SUB B
JL K
ADD B
MOV B, A
K: IN P1
JZ L
MOV A, B
OUT P2
MOV A, 0
MOV B, A
H: IN P1
JNZ H
CYCLES
800
at par
ENERGY
1600
at par
NODES
1
at par
INSTRUCTIONS
13
at par
SWAPS
8
at par