dec
Subtracts 1 from a memory cell: the cheap way to keep a countdown.
Facts
- Word
dec- Family
- Writing to memory
- Integer stack
- pops 1, pushes 0
- What it does
- Pops an address and subtracts 1 from that cell. It does not stop at 0, and below −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 dec pops the address d and subtracts 1 from whatever is in that cell. It is the twin of inc: it takes no value from the stack and costs a tenth of a store.
| Word | Stack after |
|---|---|
50 | 50 |
dec | (empty); cell 50 holds one less |
Its natural place is timers: you load a cell with a number and bring it down one at a time until it reaches 0.
' turns once every 5 cycles
cond
*50 0 >
start
50 dec
stop
cond
*50 0 =
start
100 .aimdx store
5 50 store
stopIn the first cycle cell 50 is at 0: the bot turns with .aimdx and loads it with 5. Then it goes down 4, 3, 2, 1 and is back at 0 in cycle 6, when it turns again.
dec does not stop at 0: if you do not cut it off with a condition, it keeps going negative. And below −32000 it goes back to −1. Like inc, it also does not notify the tie system if you write to .tieang1 or .tielen1; for those cells use 1 .tieang1 substore.
To subtract another amount, substore.