Syscall 2: Firmware, home

ShuffleChapter 4: Stars and hubs

S09OUT OF BREATH

The task

The breathing program, swapped about. Put it back.

Make CH1 breathe: a triangle from 0 up to 5 volts and back down, over and over.

Move the duty on P0 by 10 percent on each tick of P1, up to 100 and back down to 0.

The board

The chip of OUT OF BREATHChip u1 with 2 ports: P0 pwm out, reaching R1, C1, CH1; P1 timer 10 cycles.u1CHIP SC-2P0PWM OUTR1, C1, CH1P1TIMER 10 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 2.2 µF
Probes
CH1

Key idea

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

Two loops: one climbs until the duty reaches 100, the other falls until it reaches 0.

Hint 2Show

B holds the duty between ticks.

Hint 3Show

JNZ falls through when A is 0, which ends the falling loop by itself.

Solution

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

UP: OUT P1
MOV A, B
SUB 10
MOV B, A
SUB P0
IN UP
JNZ 100
DN: IN P1
MOV A, 10
ADD B
MOV P0, A
OUT B
JNZ DN

6 swaps back

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

  1. In core u1, swap the operand UP on line 6 with 100 on line 7.
  2. In core u1, swap the operand 10 on line 9 with B on line 10.
  3. In core u1, swap the operand P0 on line 11 with B on line 12.
  4. In core u1, swap the instruction SUB on line 3 with ADD on line 10.
  5. In core u1, swap the instruction OUT on line 1 with IN on line 6.
  6. In core u1, swap the instruction SUB on line 5 with OUT on line 6.

The finished program

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

u1SC-2 standard

UP: IN P1
MOV A, B
ADD 10
MOV B, A
OUT P0
SUB 100
JNZ UP
DN: IN P1
MOV A, B
SUB 10
MOV B, A
OUT P0
JNZ DN
CYCLES
255
at par
ENERGY
510
at par
NODES
1
at par
INSTRUCTIONS
13
at par
SWAPS
6
at par

Another way: Swap b 10

A second program that also passes, by a different road, at a cost on SWAPS.

Another arrangement that passes, one swap from the reference.

u1SC-2 standard

UP: IN P1
MOV A, 10
ADD B
MOV B, A
OUT P0
SUB 100
JNZ UP
DN: IN P1
MOV A, B
SUB 10
MOV B, A
OUT P0
JNZ DN
CYCLES
255
at par
ENERGY
510
at par
NODES
1
at par
INSTRUCTIONS
13
at par
SWAPS
7
over par