Syscall 2: Firmware, home

BenchChapter 5: Half duplex

B32ENABLE

The task

P0 reads an enable switch, a slow square wave from V1. P2 ticks every 20 cycles.

While the switch is on, blink the LED on P1: lit on odd ticks, dark on even ones.

While it is off, keep the LED dark. Check the switch on each tick.

The board

The chip of ENABLEChip 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 25 Hz
Resistors
R1 330 Ω
LEDs
D1 green
Probes
CH1 and CH2

Key idea

IN P2 gives the count of ticks so far. MOD 2 makes it 1 on odd ticks and 0 on even ones.

Hints

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

Hint 1Show

MOV B, A keeps the blink while you read the switch.

Hint 2Show

When the switch reads 0, write that 0 instead of the blink.

Solution

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

Blink on the ticks while the switch is on.

u1SC-2 standard

IN P2
MOD 2
MOV B, A
IN P0
JZ W
MOV A, B
W: OUT P1
CYCLES
254
at par
ENERGY
508
at par
NODES
1
at par
INSTRUCTIONS
7
at par