Writing to memory
The fourteen stores: the only words that change the bot's memory, and so the only way for it to do anything.
Cost: Store divided by the divisor of each one, only if it writes
| Operator | What it does |
|---|---|
store | Stores a number at a memory address: it's how every command is given, like 20 .up store to move forward. |
inc | Adds 1 to a memory cell: the cheapest counter in the DNA. |
dec | Subtracts 1 from a memory cell: the cheap way to keep a countdown. |
addstore | Adds a number to what is already in a cell, without having to read it first. |
substore | Subtracts a number from what's already in a cell: the cell minus the value. |
multstore | Multiplies what's in a cell by a number and stores the result right there. |
divstore | Divides what is in a cell by a number, rounding to the nearest integer; dividing by 0 leaves the cell at 0. |
ceilstore | Puts a ceiling on a cell: if what it holds is greater than the number, it lowers it to that number. |
floorstore | Puts a floor under a cell: if what it holds is smaller than the number, it raises it to that number. |
rndstore | Replaces what's in a cell with a random number between 0 and that value, with the same sign. |
sgnstore | Replaces what's in a cell with its sign: −1 if negative, 0 if zero, 1 if positive. |
absstore | Strips the sign from what is in a cell: a negative becomes positive. |
sqrstore | Replaces what's in a cell with its rounded square root; if it isn't positive, it leaves it at 0. |
negstore | Flips the sign of what's in a cell: 20 becomes −20 and −20 becomes 20. |
Everything a bot does goes through these words. Moving, turning, shooting or reproducing is putting a number in a sysvar, and the only things that write to memory are the stores. They all share the following:
- The address comes from the top of the integer stack; the two-operand ones also pop a value from underneath. That is why you write
value address store. - They run only inside a gene body (after
startorelse) and only if the top of the boolean stack is true or empty. A skipped store pops nothing from the stack (see Inline conditions). - Address 0 neither writes nor charges. Outside 1 to 1000 it is adjusted into the range, and the stored value is clipped to ±32000.
store is, by far, the most used: with it you give all the commands. inc and dec are the cheap counters (a tenth of the cost). The rest modify what is already in the cell without having to read it first: addstore, substore, multstore and divstore do arithmetic, ceilstore and floorstore set a ceiling or a floor, and rndstore, sgnstore, absstore, sqrstore and negstore transform the number that is stored.
They combine well on the same cell. This gene speeds up gradually and stops at a cap:
' asks for 2 more each cycle, up to 40
cond
start
2 50 addstore
40 50 ceilstore
*50 .up store
stopCell 50 goes up 2, 4, 6… to 40 and stays there, and .up receives that value every cycle. It can also be done with *50 2 add 40 ceil 50 store, but that takes more words.
The full explanation, with the family table, which addresses can be written and when the engine acts on what was written, is in Writing to memory.