Syscall 2: Firmware, home

BenchChapter 12: Shared buses

B96PATTERN

The task

P0 reads a signal on CH1. Sample it on each tick of P2; a reading DIV 33 is the bit.

Light the LED on P1 for one tick whenever the last four samples, oldest first, were 1, 0, 1, 1.

Overlapping matches count.

The board

The chip of PATTERNChip 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 1 V square at 250 Hz, V2 0.5 V square at 125 Hz, V3 0.25 V square at 62.5 Hz, and V4 1 V
Resistors
R1 330 Ω
LEDs
D1 red
Probes
CH1 and CH2

Key idea

Keep the last four samples as bits in B: double it, add the new bit, and trim with MOD 16.

Hints

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

Hint 1Show

Read as a binary number, 1, 0, 1, 1 is 11.

Hint 2Show

B minus 11 is zero on a match; write 1 then and 0 otherwise.

Solution

Reveal the Full SolutionThe complete program for PATTERN. 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 four bit shift register compared with 11.

u1SC-2 standard

IN P2
IN P0
DIV 33
ADD B
ADD B
MOD 16
MOV B, A
SUB 11
JZ H
MOV A, 0
JMP O
H: MOV A, 1
O: OUT P1
CYCLES
1177
at par
ENERGY
2354
at par
NODES
1
at par
INSTRUCTIONS
13
at par