Skip to content

The memory cell

A processor's memory dies with every edit to the program. A cell remembers — and you fetch from it by slot number

A processor’s variables are its own business: another processor cannot see them, and editing the program clears them. Shared, long-lived memory lives on the map as a separate block: a memory cell and a memory bank. read fetches a value out of it by slot number.

tick 0
Read0
=
Read1
=
Read2
=
Print3
Print4
Print5
Print6
Print Flush7
@counter0number
stocknullnull
spendnullnull
limitnullnull

The cell on this map arrived already filled: its contents are part of the save, not created fresh at start-up. The program fetches three numbers from it and prints two of them to a message block.

The line reads as “variable = where the address points”

Section titled “The line reads as “variable = where the address points””
Field What is in it
first where to put what was read
second what we read from — here a memory cell or bank, but it can be other things
third the address: a slot number, counting from zero
read stock cell1 0

A cell has 64 slots, a memory bank 512. sensor can ask the memory itself:

sensor slots cell1 @memoryCapacity

The address is truncated, and past the end lies emptiness

Section titled “The address is truncated, and past the end lies emptiness”
tick 0
Read0
=
Read1
=
Read2
=
Read3
=
Sensor4
=
in
@counter0number
fractionalnullnull
blanknullnull
pastEndnullnull
negativenullnull
slotsnullnull

Both rules are visible here at once:

  • read fractional cell1 1.9 fetches slot 1, not 2: the fractional part of an address is dropped, not rounded. 1.9 and 1.0 are the same address;
  • read pastEnd cell1 64 gives null. There are 64 slots, numbered zero to 63, and there is no sixty-fourth — but there is no error either: the variable is simply assigned emptiness. A negative address does the same;
  • read blank cell1 7 gives 0: the slot exists, it is inside the cell, and it holds a zero.

Walking the whole memory is an everyday thing, and the bound for it is better asked for than written as a number:

sensor slots cell1 @memoryCapacity
set address 0
read value cell1 address
op add sum sum value
op add address address 1
jump 2 lessThan address slots

With 64 written instead of slots, the program breaks silently the day the cell is replaced with a memory bank: it walks the first 64 slots out of 512 and decides the rest is empty.

Unofficial fan project, not affiliated with Anuke. Mindustry sprites, fonts and translations © Anuke, used under GPL-3.0; Fira Code under OFL-1.1. Site code is GPL-3.0.