Syscall 2: Firmware, home

BenchChapter 8: Scarcity

B63BROWNOUT

The task

P0 reads the supply on CH1 as a percent. P1 is the RUN line: high lets the system run.

Sample P0 on each tick of P2. Raise RUN only after 5 ticks in a row read 60 or more.

Any tick under 60 drops RUN at once and starts the count over.

The board

The chip of BROWNOUTChip u1 with 3 ports: P0 analog in, reaching V1, CH1; P1 digital out, reaching R1, D1, CH2; P2 timer 20 cycles.u1CHIP SC-2P0ANALOG 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 0.5 V, V2 1.5 V square at 35.71 Hz, V3 1.5 V square at 50 Hz, and V4 1.5 V square at 19.23 Hz
Resistors
R1 330 Ω
LEDs
D1 green
Probes
CH1 and CH2

Key idea

Count good ticks in B. A bad tick clears B and writes 0.

Hints

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

Hint 1Show

Once B reaches 5, write 1. More good ticks only keep it high.

Hint 2Show

IN P2, IN P0, SUB 60, JL to the bad branch; else add 1 to B, and write 1 once B is 5 or more.

Solution

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

A count of good ticks, cleared by any bad one.

u1SC-2 standard

L: IN P2
IN P0
SUB 60
JL BAD
MOV A, B
ADD 1
MOV B, A
SUB 5
JL L
MOV A, 1
OUT P1
JMP L
BAD: MOV A, 0
MOV B, A
OUT P1
CYCLES
663
at par
ENERGY
1326
at par
NODES
1
at par
INSTRUCTIONS
15
at par