Syscall 2: Firmware, home

BenchChapter 7: Frames and loops

B52UPHILL

The task

P0 reads a sine wave. On each tick of P2, compare the reading with the one before.

Light the LED on P1 while the wave is rising, and keep it dark while it falls.

The board

The chip of UPHILLChip 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 2 V sine at 25 Hz and V2 2.5 V
Resistors
R1 330 Ω
LEDs
D1 green
Probes
CH1 and CH2

Key idea

XCH swaps A and B, so B can hold the newest reading while A gets the old one.

Hints

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

Hint 1Show

The old reading minus the new one is below 0 when the wave climbs.

Hint 2Show

JL takes the rising case. Anything else must become 0.

Solution

Reveal the Full SolutionThe complete program for UPHILL. 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 lights while the wave climbs.

u1SC-2 standard

IN P2
IN P0
XCH
SUB B
JL ON
MOV A, 0
ON: OUT P1
CYCLES
255
at par
ENERGY
510
at par
NODES
1
at par
INSTRUCTIONS
7
at par