Syscall 2: Firmware, home

BenchChapter 11: Capstones

B82NOISE

The task

Make noise: a pseudorandom bit stream on P0, one bit for each tick of P1.

B holds 6 bits and starts at 0. The new bit is 1 when B's two lowest bits match, else 0.

Shift B right one place with DIV 2 and put the new bit on top, where it is worth 32.

Then send B's new lowest bit to P0. The pattern repeats only after 63 ticks.

The board

The chip of NOISEChip u1 with 2 ports: P0 digital out, reaching R1, D1, CH1; P1 timer 20 cycles.u1CHIP SC-2P0DIGITAL OUTR1, D1, CH1P1TIMER 20 CYCLES
The chip's ports, each with its kind and the parts its signal reaches. Cyan reads, lemon writes.
Resistors
R1 330 Ω
LEDs
D1 red
Probes
CH1

Key idea

B plus B DIV 2 has the sum of the two lowest bits as its own lowest bit.

Hints

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

Hint 1Show

Add 1 and take MOD 2, and the match test is done: 1 when they match.

Hint 2Show

Work out the new bit times 32 in A, then XCH: B DIV 2 plus that is the new B.

Solution

Reveal the Full SolutionThe complete program for NOISE. 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 six bit shift register with feedback from its two lowest bits.

u1SC-2 standard

IN P1
MOV A, B
DIV 2
ADD B
ADD 1
MOD 2
MUL 32
XCH
DIV 2
ADD B
MOV B, A
MOD 2
OUT P0
CYCLES
1028
at par
ENERGY
2056
at par
NODES
1
at par
INSTRUCTIONS
13
at par