Syscall 2: Firmware, home

BenchChapter 6: Trees

B39PRESCALER

The task

V1 drives P0 with a fast square wave. Divide it by six for the LED on P1:

count the rising edges, and keep the LED lit for counts 3, 4, and 5 of every six.

Counts 0, 1, and 2 leave it dark. The first edge is count 1.

The board

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

Key idea

A rising edge is a 1 read after a 0: wait out the high, then wait for the next one.

Hints

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

Hint 1Show

Keep the count in B. MOD 6 brings it back to 0 after 5.

Hint 2Show

DIV 3 turns counts 0 to 2 into 0 and counts 3 to 5 into 1.

Solution

Reveal the Full SolutionThe complete program for PRESCALER. 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 runs at one sixth of the input.

u1SC-2 standard

L: IN P0
JNZ L
H: IN P0
JZ H
MOV A, B
ADD 1
MOD 6
MOV B, A
DIV 3
OUT P1
CYCLES
720
at par
ENERGY
1440
at par
NODES
1
at par
INSTRUCTIONS
10
at par