Syscall 2: Firmware, home

BenchChapter 3: Chains and rings

B11RAILROAD

The task

Two lamps share the chip. P0 drives the red lamp, P1 the amber lamp.

P2 ticks every 20 cycles. Sleep on it between changes.

Trade the lamps: red on and amber off, then the other way, and repeat.

The board

The chip of RAILROADChip u1 with 3 ports: P0 digital out, reaching R1, D1, CH1; P1 digital out, reaching R2, D2, CH2; P2 timer 20 cycles.u1CHIP SC-2P0DIGITAL OUTR1, D1, CH1P1DIGITAL OUTR2, D2, CH2P2TIMER 20 CYCLES
The chip's ports, each with its kind and the parts its signal reaches. Cyan reads, lemon writes.
Resistors
R1 330 Ω and R2 330 Ω
LEDs
D1 red and D2 yellow
Probes
CH1 and CH2

Key idea

A digital output stays where you left it until the next OUT on that pin.

Hints

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

Hint 1Show

Light one lamp and put the other out before you sleep, or both glow together.

Hint 2Show

Sleep, set P0 to 1 and P1 to 0, sleep, then swap those two writes.

Solution

Reveal the Full SolutionThe complete program for RAILROAD. 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 lamps trade places each tick.

u1SC-2 standard

IN P2
MOV A, 1
OUT P0
MOV A, 0
OUT P1
IN P2
MOV A, 0
OUT P0
MOV A, 1
OUT P1
CYCLES
46
at par
ENERGY
92
at par
NODES
1
at par
INSTRUCTIONS
10
at par