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

Day 277 of 365 · Expert · Month 10: Bits and data

Rotating: rol and ror

rol and ror move bits in a circle: the game's 54-bit width, building small rings of four or eight bits yourself and a running light with a direction switch.

Lesson 16 min Week 40

What you learn today

  • Shift bits in a circle
  • 54-bit width
  • Running light

A running light: one lamp is lit, the next takes over, and after the last one it starts again at the front. With sll the bit falls out on the left and is gone. Rotating holds on to it: what falls out at the top comes back in at the bottom.

rol and ror

Instructiondoes
rol r? a nrotates a left by n places
ror r? a nrotates a right by n places

In the game both rotate within 54 bits, not 64. A bit that goes past bit 53 on the left lands in bit 0.

rol r0 %0001 1    # %0010 = 2
ror r1 %0010 1    # %0001 = 1
rol r2 %1000 2    # %10_0000 = 32

The 54-bit trap

If you rotate bit 0 right by one, it lands right at the top in bit 53. As a number that is gigantic and completely useless for four lights. Going left it also takes 54 steps until a bit is back at the front. For small running lights you therefore need a small ring of your own.

Building small rings yourself

For a ring of four bits you bring the bits that fell out back yourself: rotate left, shift everything from bit 4 to the right, put it back in and cut down to four bits:

rol pattern pattern 1
srl tmp pattern 4        # bit 4 slides to bit 0
or pattern pattern tmp
and pattern pattern $F    # keep only bits 0 to 3

Going right uses the same code: in a ring of four bits “1 to the right” is the same as “3 to the left”. With eight bits it would be 7 to the left, and instead of $F and 4 you use $FF and 8.

Running light

Each lamp gets a bit: lamp 0 is lit when bit 0 is set, and so on. You get the bit out with srl and and 1 – tomorrow that works in one line with ext.

Tip

A tick lasts 0.5 s. If you rotate every tick, the light moves two steps per second. It gets slower with a counter that only lets it rotate every n-th tick.

Warning

Rotating is not arithmetic. sll doubles a number until bits fall out on the left. rol only doubles as long as the top bit is free – after that it reappears at the bottom and the number suddenly becomes small.

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
Rotating loses no bit: what falls out at the top comes back in at the bottom.

Exercise

Task

Build a running light over the four lights “LL0” to “LL3”. pattern starts at 1. Every tick the light moves on by one lamp:

  • switch “Richtung” closed (Open 0) or missing: upwards (LL0 → LL1 → LL2 → LL3 → LL0)
  • switch open: downwards
  • exactly one lamp is always lit

Hints

Hint 1

Step size with select: 1 upwards, 3 downwards (ring of four bits).

Hint 2

After rol: srl tmp pattern 4, or, and pattern pattern $F.

Hint 3

Lamp n: srl tmp pattern n, and tmp tmp 1, sbn ….

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