Syscall 2: Firmware, home

BenchChapter 5: Half duplex

B26ALARM

The task

P0 is an analog input: IN P0 reads its voltage as a percent of the 5 volt supply.

Sound the alarm: light the LED on P1 while the input is above 3 volts.

Keep it dark the rest of the time.

The board

The chip of ALARMChip u1 with 2 ports: P0 analog in, reaching V1, CH1; P1 digital out, reaching R1, D1, CH2.u1CHIP SC-2P0ANALOG INV1, CH1P1DIGITAL OUTR1, D1, CH2
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 triangle at 50 Hz and V2 2.5 V
Resistors
R1 330 Ω
LEDs
D1 red
Probes
CH1 and CH2

Key idea

3 volts is 60 percent of the supply.

Hints

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

Hint 1Show

Subtract 60. JG jumps when what is left is above 0.

Hint 2Show

A positive A lights the LED as it is. Anything else must become 0 before OUT P1.

Solution

Reveal the Full SolutionThe complete program for ALARM. 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 lights above 3 volts.

u1SC-2 standard

IN P0
SUB 60
JG W
MOV A, 0
W: OUT P1
CYCLES
400
at par
ENERGY
800
at par
NODES
1
at par
INSTRUCTIONS
5
at par