Syscall 2: Firmware, home

BenchChapter 3: Chains and rings

B04STAIRCASE

The task

Build a staircase on CH1: five steps from 0 to 5 volts, then start over.

Climb one step on each tick of P1. P0 is a PWM pin into R1 and C1.

The board

The chip of STAIRCASEChip u1 with 2 ports: P0 pwm out, reaching R1, C1, CH1; P1 timer 40 cycles.u1CHIP SC-2P0PWM OUTR1, C1, CH1P1TIMER 40 CYCLES
The chip's ports, each with its kind and the parts its signal reaches. Cyan reads, lemon writes.
Resistors
R1 1 kΩ
Capacitors
C1 1 µF
Probes
CH1

Key idea

Each step is a quarter of the supply: 25 percent more duty.

Hints

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

Hint 1Show

MOV B, A copies A into B, and MOV A, B copies it back, so B can hold the duty between ticks.

Hint 2Show

After 100 percent the next step is 0.

Solution

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

MOV A, B
OUT P0
ADD 25
MOV B, A
SUB 125
JNZ W
MOV B, A
W: IN P1
CYCLES
72
at par
ENERGY
144
at par
NODES
1
at par
INSTRUCTIONS
8
at par

Another way: Mod

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

MOD 125 wraps the duty in one line.

u1SC-2 standard

MOV A, B
OUT P0
ADD 25
MOD 125
MOV B, A
IN P1
CYCLES
60
under par
ENERGY
120
under par
NODES
1
at par
INSTRUCTIONS
6
under par