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

Day 121 of 365 · Advanced · Month 5: Memory and structure

poke and the stack as a table

poke writes to a fixed address in the stack without moving sp. With fixed addresses the stack becomes a table that you read with get.

Lesson 12 min Week 18

What you learn today

  • poke writes to an address
  • sp stays put
  • Use the stack as a table

With push and pop the stack works like a pile of plates. Sometimes, though, you want to write to a particular place without clearing away everything above it. That is what poke is for.

poke writes to an address

poke 5 293.15     # address 5 = 293.15
get r0 db 5       # r0 = 293.15

poke address value writes the value straight to the address. You read it with get r? db address, which you already know. Neither changes sp.

Instructionwrites / readssp
push valueat address spgrows by 1
pop r?from address sp − 1shrinks by 1
poke adr valueat address adrstays
put db adr valueat address adrstays
get r? db adrfrom address adrstays

poke adr value and put db adr value do the same. poke is shorter, put can also write into the stack of other devices.

The stack as a table

With fixed addresses the stack becomes a table. An example: five light programmes for the bar, each with one colour:

poke 0 Color.White
poke 1 Color.Blue
poke 2 Color.Green
poke 3 Color.Orange
poke 4 Color.Red

Filling sits before the start label and runs once. In the main loop a get is then enough:

lbn prog DIAL HASH("Barlicht") Setting Average
get colour db prog

The dial position is directly the address in the table.

Warning

An address above 511 reports StackOverFlow, a negative one StackUnderFlow. If the address comes from outside, for instance from a dial, limit it beforehand with max and min. NaN does not belong in an address either, catch it first.

Tip

If you mix push and poke in the same stack, put the table at fixed addresses far up, such as from 400. The push pile grows upwards from 0 and will not get in its way so soon.

Diagram

The stack with its pointer slot 0 10 slot 1 20 slot 2 30 slot 3 slot 4 sp = 3 next free slot push 40 pop r0 r0 = 30 last in, first out
push and pop work at the top of the pile and move sp. poke and get access a fixed address.

Exercise

Task

Five light programmes for the bar. The dial “Barlicht” picks the programme 0 to 4, the LEDs “Bar” (StructureDiode) get the colour.

  • Before the start label fill the table with poke: 0 Color.White, 1 Color.Blue, 2 Color.Green, 3 Color.Orange, 4 Color.Red.
  • In the loop read the colour from the table with get.
  • Limit the position to 0 to 4. If the dial is missing, programme 0 applies. sp stays 0 throughout.

Hints

Hint 1

Five poke lines before start:.

Hint 2

Replace NaN with 0 using snan and select, then max … 0 and min … LAST.

Hint 3

get colour db prog fetches the colour without changing sp.

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