inc
Adds 1 to a memory cell: the cheapest counter in the DNA.
Facts
- Word
inc- Family
- Writing to memory
- Integer stack
- pops 1, pushes 0
- What it does
- Pops an address and adds 1 to that cell. Past 32000 it wraps back to 1. With address 0 it does nothing.
- Cost
- Store divided by the divisor of each one, only if it writes
- Cost divisor
- ÷ 10
- Runs
- in the body of a gene (start or else), and only if the top of the boolean stack is true or the stack is empty
- Marks ties
- no
d inc pops the address d and adds 1 to whatever is in that cell. It takes no value from the stack: 50 inc is the same as *50 1 add 50 store, but in two words and for a tenth of the cost of a store.
| Word | Stack afterwards |
|---|---|
50 | 50 |
inc | (empty); cell 50 holds one more |
The typical use is counting cycles in free memory, which is not cleared between one cycle and the next:
' counts cycles in cell 50 and turns every 10
start
50 inc
stop
cond
*50 10 >=
start
0 50 store
100 .aimdx store
stopCell 50 goes from 1 to 9; in the tenth cycle it reaches 10, the second gene sets it back to 0 and the bot turns 100 with .aimdx. So it turns once every 10 cycles.
Two things to keep in mind:
- If you let it count without a limit, after 32000 it doesn't keep going or turn negative: it wraps back to 1.
- On
.tieang1or.tielen1it changes the number, but the tie doesn't find out. For those cells use1 .tieang1 addstore(see Writing to memory).
To subtract 1 there is dec; to add another amount, addstore.