Syscall 2: Firmware, home

BenchChapter 6: Trees

B41DELAY LINE

The task

On each tick of P2, sample P0, and light the LED on P1 the way P0 read on the tick before.

The LED repeats the input one tick late.

The board

The chip of DELAY LINEChip u1 with 3 ports: P0 digital in, reaching V1, CH1; P1 digital out, reaching R1, D1, CH2; P2 timer 20 cycles.u1CHIP SC-2P0DIGITAL INV1, CH1P1DIGITAL OUTR1, D1, CH2P2TIMER 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 square at 40 Hz
Resistors
R1 330 Ω
LEDs
D1 yellow
Probes
CH1 and CH2

Key idea

XCH swaps A and B.

Hints

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

Hint 1Show

Keep the newest sample in B, and write out the one it replaces.

Hint 2Show

Sleep, read P0, swap, and write.

Solution

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

The LED shows the input one tick late.

u1SC-2 standard

IN P2
IN P0
XCH
OUT P1
CYCLES
157
at par
ENERGY
314
at par
NODES
1
at par
INSTRUCTIONS
4
at par