Syscall 2: Firmware, home

BenchChapter 3: Chains and rings

B07BAR GRAPH

The task

P0 is an analog input: IN P0 reads its voltage as a percent of the 5 volt supply.

Light an LED for each quarter of the supply the input reaches:

P1 from 25 percent, P2 from 50, and P3 from 75.

Sample the input on each tick of P4.

The board

The chip of BAR GRAPHChip u1 with 5 ports: P0 analog in, reaching V2, CH1; P1 digital out, reaching R1, D1, CH2; P2 digital out, reaching R2, D2, CH3; P3 digital out, reaching R3, D3, CH4; P4 timer 20 cycles.u1CHIP SC-2P0ANALOG INV2, CH1P1DIGITAL OUTR1, D1, CH2P2DIGITAL OUTR2, D2, CH3P3DIGITAL OUTR3, D3, CH4P4TIMER 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.5 V and V2 2.5 V triangle at 50 Hz
Resistors
R1 330 Ω, R2 330 Ω, and R3 330 Ω
LEDs
D1 green, D2 yellow, and D3 red
Probes
CH1, CH2, CH3, and CH4

Key idea

DIV 25 turns the reading into the number of quarters it has reached.

Hints

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

Hint 1Show

A digital output is on for any value but 0, so a quotient of 1 or more lights an LED.

Hint 2Show

CH1 is the input; CH2 to CH4 are the LEDs.

Solution

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

IN P4
IN P0
MOV B, A
DIV 25
OUT P1
MOV A, B
DIV 50
OUT P2
MOV A, B
DIV 75
OUT P3
CYCLES
210
at par
ENERGY
420
at par
NODES
1
at par
INSTRUCTIONS
11
at par

Another way: Quarters

A second program that also passes, and beats par on CYCLES, ENERGY, and INSTRUCTIONS.

One division: the quarters, then halves and thirds of the quarters.

u1SC-2 standard

IN P4
IN P0
DIV 25
OUT P1
MOV B, A
DIV 2
OUT P2
MOV A, B
DIV 3
OUT P3
CYCLES
191
under par
ENERGY
382
under par
NODES
1
at par
INSTRUCTIONS
10
under par