What you learn today
- Connect several stores
- Requests
- Priorities
The smelter needs steel, the workshop iron, and both call at the same time. A logistics hub collects such requests, decides who goes first and sends from the right store.
Connecting several stores
The stores are vending machines with their own names on the same data network: “Zentrallager” for everyday use, “Reservelager” for emergencies. A chip reaches both via sbn with the name. Whether the central store still has something is revealed by Ratio.
Requests
Every station has a logic memory (“BedarfHuette”, “BedarfWerkstatt”). It writes the prefab hash of what it needs into it – for example from the rmap chip at the lathe. 0 means: nothing needed.
The hub reads the memory, delivers and acknowledges by resetting the memory to 0. That way every request is served exactly once.
jal deliver
sbn MEMORY HASH("BedarfHuette") Setting 0
Priorities
The order in the code is the priority: the smelter is asked first. If it has a request, it gets served, and the chip jumps back to the start – the workshop's turn comes in the next tick. Only when the smelter needs nothing does it check the workshop.
One subroutine for delivering
Where to deliver from is decided by a subroutine: the central store while it is more than 5 % filled, otherwise the reserve. Both stations call the same subroutine with jal; the request is in req.
deliver:
lbn tmp VENDING HASH("Zentrallager") Ratio Average
sge tmp tmp EMPTY
beqz tmp reserve
If the central store is missing, Ratio is NaN, sge gives 0 – the reserve steps in.
A hash can be negative. So check requests for “not equal to 0” (beqz), never for “greater than 0”. And catch NaN beforehand: select would otherwise take a missing memory for a request.
Diagram
Exercise
Task
Two logic memories “BedarfHuette” and “BedarfWerkstatt” contain a prefab hash or 0. Serve one request per tick, the smelter first: a subroutine deliver writes the hash as RequestHash to the vending machine “Zentrallager” – or to “Reservelager” if the central store is below 5 % filled or missing. Afterwards the chip sets the served memory to 0.
Hints
Hint 1
Per station: read the memory, turn NaN into 0 with snan/select, move on at 0.
Hint 2
Serving: jal deliver, then set the memory to 0 and j start.
Hint 3
deliver: the central store's Ratio with sge against EMPTY, otherwise to the reserve; return with j ra.
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