Syscall 2: Firmware, home

ShuffleChapter 11: Capstones

S41SECOND THOUGHTS

The task

A trigger that takes its time, with every piece out of place.

P0 reads a sine that swings from 10 to 90 percent of the supply.

Turn P1 full on once P0 reaches 70 percent, and off once it falls to 30.

The board

The chip of SECOND THOUGHTSChip u1 with 2 ports: P0 analog in, reaching V2, CH1; P1 pwm out, reaching R1, C1, CH2.u1CHIP SC-2P0ANALOG INV2, CH1P1PWM OUTR1, C1, CH2
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 and V2 2 V sine at 50 Hz
Resistors
R1 1 kΩ
Capacitors
C1 1 µF
Probes
CH1 and CH2

Key idea

Par is 7 swaps. Core u1 needs 2 instruction swaps and 5 operand swaps. 5 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

Wait in one loop until the input reaches 70, and in another until it falls to 30.

Hint 2Show

JL loops while the input is still under 70, and JG while it is still over 30.

Hint 3Show

Between the two, the output keeps whatever it was last set to.

Solution

Reveal the Full SolutionThe complete program for SECOND THOUGHTS. 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: SUB P0
IN H
IN P1
MOV A, P1
OUT L
H: JL A
SUB 30
JG P0
MOV 70, 0
OUT 100

7 swaps back

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

  1. In core u1, swap the operand P1 on line 3 with L on line 5.
  2. In core u1, swap the operand P1 on line 4 with 100 on line 10.
  3. In core u1, swap the operand H on line 2 with 70 on line 9.
  4. In core u1, swap the operand A on line 6 with P0 on line 8.
  5. In core u1, swap the operand A on line 8 with H on line 9.
  6. In core u1, swap the instruction SUB on line 1 with IN on line 2.
  7. In core u1, swap the instruction IN on line 3 with JL on line 6.

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 70
JL L
MOV A, 100
OUT P1
H: IN P0
SUB 30
JG H
MOV A, 0
OUT P1
CYCLES
400
at par
ENERGY
800
at par
NODES
1
at par
INSTRUCTIONS
10
at par
SWAPS
7
at par