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

Day 248 of 365 · Pro · Month 9: Logistics and greenhouse

Inventory in the stack

A stock table in the stack: store hash and amount in pairs, sort every slot of a locker into it and search for a hash.

Lesson 25 min Week 36

What you learn today

  • Stock per item
  • Table with hash and quantity
  • Search

“How much copper do we have?” In the ingot locker copper lies in three different slots, with iron and steel in between. Instead of searching all 30 slots for copper every time, the chip builds a table: one row per kind, hash and amount.

Stock per item

Every row has two places in the stack: the prefab hash on the even address, the amount on the odd one behind it.

RowHash addressAmount address
001
123
245
367

The chip stores the hashes once before the start label:

poke 0 IRON
poke 2 COPPER

Filling the table

Every pass the chip sets all amounts to 0 and then goes through the locker's slots. For every slot it looks for the matching row and adds the amount:

row:
mul addr j 2
get tmp db addr
beq tmp kind hit
add j j 1
blt j ROWS row

Empty slots have the hash 0, which stands in no row – they simply fall through. Kinds that are not in the table do the same.

The search goes through the table once and returns the amount for the wanted kind. Not found means −1. Somebody writes the wanted hash into a logic memory “Suche” – a player via a console or another chip.

Tip

30 slots times up to four rows are a good 900 instructions – the chip needs about eight ticks for a whole pass. That is why the display does not jump in the same tick in which an ingot arrives. For a store that is perfectly fine.

Warning

In the middle of a pass the table holds half sums. Whoever reads the table from outside with get, for example a second chip, then sees wrong numbers. Only read it at the end of the pass – or write the finished values into a second area.

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
Even addresses hold the hash, the odd one behind it the amount. Row j lies at 2 · j.

Exercise

Task

The table lives in addresses 0–7 (iron, copper, steel, silicon). Every pass set the amounts to 0, sort all 30 slots of the locker “Barren” into it and show on “Bestand” the amount for the hash in the logic memory “Suche”: −1 when the kind is not in the table, −2 when the locker is missing.

Hints

Hint 1

Clearing amounts: address 2 · j + 1 with poke … 0.

Hint 2

Per slot: find the row with get tmp db addr and beq tmp kind hit, then add the amount.

Hint 3

Search: amount first −1, on a hit get amount db addr; finally a missing locker with −2.

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