stationeers.de Mod workshop · Dominik1199
DE Sign in
  1. Home
  2. IC10 academy
  3. Day 15

Day 15 of 365 · Beginner · Month 1: First steps

yield and the main loop

Ticks, the 128-instruction limit and why every program needs an endless loop.

Lesson 9 min Week 3

What you learn today

  • Ticks and the 128-instruction limit
  • Endless loop with label and j
  • Place yield correctly

The programs so far ran once and were done. For a controller that is useless: the temperature keeps changing, so the chip has to measure again and again.

When the chip runs off the end

When the chip reaches the end of the program, it stops for good – no error, no light. It does not restart on its own either. Only pulling the chip and putting it back in wakes it up. That is why every real program ends with a jump back to the start:

start:
yield
l r0 d0 Temperature
sub r0 r0 273.15
s d1 Setting r0
j start

start: is a label, a jump target. j start jumps there. More about labels in the next lesson.

Ticks and yield

The game computes in ticks of 0.5 seconds. Per tick the chip runs at most 128 instructions, then it waits for the next tick. Device values only change between ticks.

yield says: “I am done for this tick.” Without yield the loop spins for 128 instructions and keeps reading the same value – nothing visible breaks, but it is pointless and makes programs hard to predict.

Tip

Rule of thumb: put a yield right after the start label. Then the loop runs exactly once per tick.

sleep

sleep 5 waits five seconds (not ticks) and replaces the yield. Handy for blinking lights or slow sequences.

Diagram

Ticks and yield on a timeline tick 0 · 0.0 s tick 1 · 0.5 s tick 2 · 1.0 s tick 3 · 1.5 s 5 instr. yield 5 instr. yield 5 instr. yield 128 instr. no yield: limit hit Device values only change between two ticks.
Per tick (0.5 s) the chip runs at most 128 instructions. yield ends the tick right away, the next tick continues on the line after it.

Exercise

Task

Turn the temperature display into a continuous controller: the display on d1 should show the temperature of the sensor on d0 in °C – all the time, even when the value changes. Build an endless loop with yield.

Hints

Hint 1

Put a label above the first instruction, e.g. start: – alone on its line.

Hint 2

Below it yield, at the very end j start.

Quiz

4 questions. You pass from 60 % – the server does the grading.

Complete the day

  • Passed the simulator exercise
  • Passed the quiz with at least 60 %

Without an account progress is saved in this browser only.

Report a mistake in this lesson

Please sign in to report. Sign in

Esc
↑ ↓ selectEnter open/ opens search anywhere