Syscall 2: Firmware, home

ShuffleChapter 4: Stars and hubs

S07SPILLED BARS

The task

The bar graph program is here, swapped about. Swap it back.

Light an LED for each quarter of the supply the input on P0 reaches:

P1 from 25 percent, P2 from 50, and P3 from 75, sampled on each tick of P4.

The board

The chip of SPILLED BARSChip u1 with 5 ports: P0 analog in, reaching V2, CH1; P1 digital out, reaching R1, D1, CH2; P2 digital out, reaching R2, D2, CH3; P3 digital out, reaching R3, D3, CH4; P4 timer 20 cycles.u1CHIP SC-2P0ANALOG INV2, CH1P1DIGITAL OUTR1, D1, CH2P2DIGITAL OUTR2, D2, CH3P3DIGITAL OUTR3, D3, CH4P4TIMER 20 CYCLES
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.5 V triangle at 50 Hz
Resistors
R1 330 Ω, R2 330 Ω, and R3 330 Ω
LEDs
D1 green, D2 yellow, and D3 red
Probes
CH1, CH2, CH3, and CH4

Key idea

Par is 4 swaps. Core u1 needs 1 instruction swap and 3 operand swaps. Every one of them trades two tiles that hold each other's places, so each swap mends two.

Hints

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

Hint 1Show

IN P0 reads the input as a percent of the 5 volt supply.

Hint 2Show

DIV 25 turns the reading into the number of quarters it has reached.

Hint 3Show

MOV A, B brings the reading back for the next LED.

Solution

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

OUT P4
IN B
MOV P0, B
DIV 25
OUT A
MOV A, B
DIV 50
OUT P2
MOV P1, A
DIV 75
IN P3

4 swaps back

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

  1. In core u1, swap the operand B on line 2 with P0 on line 3.
  2. In core u1, swap the operand B on line 3 with A on line 9.
  3. In core u1, swap the operand A on line 5 with P1 on line 9.
  4. In core u1, swap the instruction OUT on line 1 with IN on line 11.

The finished program

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

u1SC-2 standard

IN P4
IN P0
MOV B, A
DIV 25
OUT P1
MOV A, B
DIV 50
OUT P2
MOV A, B
DIV 75
OUT P3
CYCLES
210
at par
ENERGY
420
at par
NODES
1
at par
INSTRUCTIONS
11
at par
SWAPS
4
at par