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

Day 102 of 365 · Advanced · Month 4: Network in detail

Indirect: dr0 and rr0

dr0 is the pin whose number sits in r0, rr1 the register whose number sits in r1. With that a loop runs over all pins and fills a table.

Lesson 14 min Week 15

What you learn today

  • Pin number from a register
  • Register via register
  • Loop over pins

In the control cabinet four sensors hang on d0 to d3. Writing four almost identical blocks is tedious, and with six pins it does not get better. Better: the pin number sits in a register, and a loop goes through them.

dr0: a pin from a register

dr2 means: the pin whose number is currently in r2. If r2 holds a 3, dr2 is the same as d3.

move i 0
pin:
l temp dr0 Temperature    # dr0: pin with the number from r0
add i i 1
blt i 4 pin

This works wherever a pin may appear: l, s, ls, sdse, bdns and so on.

Warning

dr0 contains the register number, not the alias. If i is an alias for r0, the pin is still called dr0. There is no dri. If someone moves the alias to another register, dr0 has to follow.

rr1: register via register

The same exists for registers. rr1 means: the register whose number sits in r1.

move r1 10
move rr1 42        # writes 42 to r10
add r1 r1 1
move rr1 43        # writes 43 to r11

That way you build a small table in the registers, for instance the temperatures of four pins in r10 to r13. Several r work too: rrr1 first reads r1, takes the value as a register number, reads there and takes that value as the number.

If a register number lies outside 0 to 17, the chip reports OutOfRegisterBounds. A pin number outside 0 to 5 also leads to an error.

Loop over pins

Put together, this gives a loop that checks every pin, reads it and puts the value into its own register:

move i 0
pin:
add target i 10        # target registers r10 to r13
move rr1 0             # start value in case the pin is empty
bdns dr0 next
l rr1 dr0 Temperature
next:
add i i 1
blt i 4 pin

Here i is an alias for r0 and target an alias for r1.

Tip

For tables with more than a few entries the stack is better. Registers are scarce, and rr eats them quickly. The stack comes in week 18.

Diagram

The register bank of the chip r0 42 r1 31 r2 10 r3 -2.5 r4 0 r5 0 r6 0 r7 0 r8 0 r9 0 r10 0 r11 0 r12 0 r13 0 r14 0 r15 0 sp = r16 ra = r17 16 free registers, one number each sp: stack pointer · ra: return address
An extra r in front of the register means: take the content as a number. dr0 picks a pin that way, rr1 a register.

Exercise

Task

Gas sensors may hang on d0 to d3, some pins are empty.

  • In a loop over the pins read the temperatures into r10 to r13 (pin d0 → r10 and so on), using dr0 and rr1.
  • An empty pin gives 0 in its register.
  • Write the highest temperature (in K) as Setting to the housing (db), 0 if no sensor is there.

Hints

Hint 1

i is r0, so the pin is dr0. target is r1, so the target register is rr1.

Hint 2

Inside the loop: add target i 10, move rr1 0, bdns dr0 next, l rr1 dr0 Temperature.

Hint 3

Collect the maximum with max highest highest rr1.

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