Syscall 2: Firmware, home

BenchChapter 6: Trees

B37ONE SHOT

The task

V1 drives P0 with a slow square wave. On each rising edge, light the LED on P1 for 30 cycles.

Then put it out and wait for the next rising edge. Every instruction takes one cycle.

The board

The chip of ONE SHOTChip u1 with 2 ports: P0 digital in, reaching V1, CH1; P1 digital out, reaching R1, D1, CH2.u1CHIP SC-2P0DIGITAL 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 5 V square at 50 Hz
Resistors
R1 330 Ω
LEDs
D1 yellow
Probes
CH1 and CH2

Key idea

A rising edge is a 1 read after a 0: wait while P0 reads 1, then wait while it reads 0.

Hints

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

Hint 1Show

A countdown loop of SUB 1 and JNZ spends two cycles a pass.

Hint 2Show

MOV A, 14 before the loop gives 28 cycles, and the lines around it make up the rest.

Solution

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

30 cycles of light after each rising edge.

u1SC-2 standard

L: IN P0
JNZ L
H: IN P0
JZ H
MOV A, 1
OUT P1
MOV A, 14
W: SUB 1
JNZ W
OUT P1
CYCLES
800
at par
ENERGY
1600
at par
NODES
1
at par
INSTRUCTIONS
10
at par