Syscall 2: Firmware, home

BenchChapter 11: Capstones

B83STRETCH

The task

P0 reads pulses of different lengths on CH1. Sample it on each tick of P2.

Light the LED on P1 while a pulse is high, then keep it lit as many ticks again after it falls.

A pulse of 6 ticks lights the LED for 12.

The board

The chip of STRETCHChip u1 with 3 ports: P0 digital in, reaching V1, CH1; P1 digital out, reaching R1, D1, CH2; P2 timer 20 cycles.u1CHIP SC-2P0DIGITAL 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 2 V square at 25 Hz and V2 1.2 V square at 62.5 Hz
Resistors
R1 330 Ω
LEDs
D1 yellow
Probes
CH1 and CH2

Key idea

Count the ticks the input reads high in B.

Hints

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

Hint 1Show

After it falls, count B back down to zero, one per tick, with the LED still lit.

Hint 2Show

When the count reaches zero, put the LED out and wait for the next pulse.

Solution

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

Count up while high, count down after, lit until zero.

u1SC-2 standard

L: IN P2
IN P0
JZ E
OUT P1
MOV A, B
ADD 1
MOV B, A
JMP L
E: MOV A, B
JZ L
SUB 1
MOV B, A
JNZ L
OUT P1
CYCLES
586
at par
ENERGY
1172
at par
NODES
1
at par
INSTRUCTIONS
14
at par