Syscall 2: Firmware, home

BenchChapter 8: Scarcity

B55IDEAL DIODE

The task

Two diodes joined at their cathodes pass whichever input is higher, less 0.6 volts.

Do it without the loss: put out the higher of P0 and P1 on CH3 through the PWM pin P2.

The board

The chip of IDEAL DIODEChip u1 with 3 ports: P0 analog in, reaching V1, CH1; P1 analog in, reaching V3, CH2; P2 pwm out, reaching R1, C1, CH3.u1CHIP SC-2P0ANALOG INV1, CH1P1ANALOG INV3, CH2P2PWM OUTR1, C1, CH3
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, V2 2.5 V, and V3 3 V square at 10 Hz
Resistors
R1 1 kΩ
Capacitors
C1 1 µF
Probes
CH1, CH2, and CH3

Key idea

MOV B, A keeps the first reading.

Hints

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

Hint 1Show

The second reading minus the first is above 0 only when the second is higher.

Hint 2Show

If it is not, start from 0. Either way, ADD B gives the higher reading.

Solution

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

Put out the higher of two inputs, with no drop.

u1SC-2 standard

IN P0
MOV B, A
IN P1
SUB B
JG W
MOV A, 0
W: ADD B
OUT P2
CYCLES
1000
at par
ENERGY
2000
at par
NODES
1
at par
INSTRUCTIONS
8
at par