Syscall 2: Firmware, home

BenchChapter 6: Trees

B38LATCH

The task

P0 is SET and P1 is RESET, two square waves from V1 and V2. P2 drives the LED.

SET high lights the LED and RESET high puts it out. When both are high, RESET wins.

When both are low, leave the LED as it was.

The board

The chip of LATCHChip u1 with 3 ports: P0 digital in, reaching V1, CH1; P1 digital in, reaching V2, CH2; P2 digital out, reaching R1, D1, CH3.u1CHIP SC-2P0DIGITAL INV1, CH1P1DIGITAL INV2, CH2P2DIGITAL OUTR1, D1, CH3
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 and V2 5 V square at 62.5 Hz
Resistors
R1 330 Ω
LEDs
D1 red
Probes
CH1, CH2, and CH3

Key idea

A pin keeps its level until the next OUT, so doing nothing is how the LED remembers.

Hints

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

Hint 1Show

Check RESET first. Only when it is low does SET get a say.

Hint 2Show

When both read 0, jump back to the top without an OUT.

Solution

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

SET lights it, RESET puts it out, and it remembers between.

u1SC-2 standard

L: IN P1
JNZ OFF
IN P0
JZ L
OUT P2
JMP L
OFF: MOV A, 0
OUT P2
CYCLES
800
at par
ENERGY
1600
at par
NODES
1
at par
INSTRUCTIONS
8
at par