Syscall 2: Firmware, home

BenchChapter 7: Frames and loops

B45SCANNER

The task

These LEDs hang from V1 and light when their pin pulls low: a pin at 0 lights its LED.

On each tick of P3, move the light one place, P0 to P1 to P2 and back, starting at P0.

The board

The chip of SCANNERChip u1 with 4 ports: P0 digital out, reaching R1, D1, V1, CH1; P1 digital out, reaching R2, D2, V1, CH2; P2 digital out, reaching R3, D3, V1, CH3; P3 timer 20 cycles.u1CHIP SC-2P0DIGITAL OUTR1, D1, V1, CH1P1DIGITAL OUTR2, D2, V1, CH2P2DIGITAL OUTR3, D3, V1, CH3P3TIMER 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 5 V
Resistors
R1 330 Ω, R2 330 Ω, and R3 330 Ω
LEDs
D1 red, D2 red, and D3 red
Probes
CH1, CH2, and CH3

Key idea

Any value but 0 keeps an LED dark here, so write 0 only to the pin whose turn it is.

Hints

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

Hint 1Show

With the place of the light in A, OUT P0, SUB 1, OUT P1, SUB 1, OUT P2 does the rest.

Hint 2Show

The place runs 0, 1, 2, 1. Count the ticks around 0 to 3, then fold 3 back to 1.

Solution

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

The reference program

The game's own solution. It passes every test and scores exactly par on every benchmark.

One light runs back and forth on pins that sink.

u1SC-2 standard

IN P3
ADD 3
MOD 4
SUB 2
JL S
NEG
S: ADD 2
OUT P0
SUB 1
OUT P1
SUB 1
OUT P2
CYCLES
219
at par
ENERGY
438
at par
NODES
1
at par
INSTRUCTIONS
12
at par