Syscall 2: Firmware, home

BenchChapter 3: Chains and rings

B05DIVIDER

The task

V1 sends a square wave into P0, a digital input.

IN P0 reads 1 while the input is high and 0 while it is low.

Toggle the LED on P1 at every rising edge of the input, so it blinks at half the rate.

The board

The chip of DIVIDERChip 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 for the high, then wait for the low.

Hints

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

Hint 1Show

1 minus the LED's last state is its next state. B can keep the state.

Hint 2Show

CH1 shows the input and CH2 the LED.

Solution

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

u1SC-2 standard

L: IN P0
JZ L
MOV A, 1
SUB B
MOV B, A
OUT P1
H: IN P0
JNZ H
CYCLES
400
at par
ENERGY
800
at par
NODES
1
at par
INSTRUCTIONS
8
at par

Another way: Xch

A second program that also passes, by a different road, at a cost on INSTRUCTIONS.

Keeps the state in B with XCH and flips it with NEG.

u1SC-2 standard

L: IN P0
JZ L
XCH A, B
NEG
ADD 1
OUT P1
XCH A, B
H: IN P0
JNZ H
CYCLES
400
at par
ENERGY
800
at par
NODES
1
at par
INSTRUCTIONS
9
over par