Syscall 2: Firmware, home

ShuffleChapter 7: Frames and loops

S27COMEDOWN

The task

The landing program, swapped about. Swap it back.

P0 is a PWM pin into R1 and C1, and P1 ticks every 40 cycles.

Step CH1 down: full, three quarters, half, a quarter, and off, then full again.

The board

The chip of COMEDOWNChip u1 with 2 ports: P0 pwm out, reaching R1, C1, CH1; P1 timer 40 cycles.u1CHIP SC-2P0PWM OUTR1, C1, CH1P1TIMER 40 CYCLES
The chip's ports, each with its kind and the parts its signal reaches. Cyan reads, lemon writes.
Resistors
R1 1 kΩ
Capacitors
C1 1 µF
Probes
CH1

Key idea

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

B keeps the duty across the sleep on P1. MOV A, B brings it back.

Hint 2Show

SUB 25 drops one step. At 0 the next duty is 100, not a negative step.

Hint 3Show

JZ takes the reset and JMP skips it, so both paths meet at MOV B, A.

Solution

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

MOV A, B
IN 100
OUT A
SUB 25
JZ K
F: MOV F, P0
K: MOV B, A
JMP P1

5 swaps back

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

  1. In core u1, swap the operand 100 on line 2 with P0 on line 6.
  2. In core u1, swap the operand A on line 3 with F on line 6.
  3. In core u1, swap the instruction IN on line 2 with OUT on line 3.
  4. In core u1, swap the instruction IN on line 3 with JZ on line 5.
  5. In core u1, swap the instruction IN on line 5 with JMP on line 8.

The finished program

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

u1SC-2 standard

MOV A, B
OUT P0
JZ F
SUB 25
JMP K
F: MOV A, 100
K: MOV B, A
IN P1
CYCLES
68
at par
ENERGY
136
at par
NODES
1
at par
INSTRUCTIONS
8
at par
SWAPS
5
at par