Syscall 2: Firmware, home

BenchChapter 3: Chains and rings

B08BREATHE

The task

Make CH1 breathe: a triangle from 0 up to 5 volts and back down, over and over.

Move the duty on P0 by 10 percent on each tick of P1, up to 100 and back down to 0.

The board

The chip of BREATHEChip u1 with 2 ports: P0 pwm out, reaching R1, C1, CH1; P1 timer 10 cycles.u1CHIP SC-2P0PWM OUTR1, C1, CH1P1TIMER 10 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 2.2 µF
Probes
CH1

Key idea

Two loops: one climbs until the duty reaches 100, the other falls until it reaches 0.

Hints

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

Hint 1Show

B can hold the duty between ticks.

Hint 2Show

JNZ falls through when A is 0, which ends the falling loop by itself.

Solution

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

UP: IN P1
MOV A, B
ADD 10
MOV B, A
OUT P0
SUB 100
JNZ UP
DN: IN P1
MOV A, B
SUB 10
MOV B, A
OUT P0
JNZ DN
CYCLES
255
at par
ENERGY
510
at par
NODES
1
at par
INSTRUCTIONS
13
at par

Another way: Sign

A second program that also passes, and matches par on every benchmark.

The falling loop adds a negative step and runs while the duty is above 0.

u1SC-2 standard

UP: IN P1
MOV A, B
ADD 10
MOV B, A
OUT P0
SUB 100
JNZ UP
DN: IN P1
MOV A, B
ADD -10
MOV B, A
OUT P0
JG DN
CYCLES
255
at par
ENERGY
510
at par
NODES
1
at par
INSTRUCTIONS
13
at par