DEC DEC Decrement memory by one DEC
Operation: M - 1 -> M N V - B D I Z C
/ . . . . . / .
+----------------+-----------------------+---------+---------+----------+
| Addressing Mode| Assembly Language Form| OP CODE |No. Bytes|No. Cycles|
+----------------+-----------------------+---------+---------+----------+
| ZeroPage | DEC $FF | $C6 | 2 | 5 |
| ZeroPage,X | DEC $FF,X | $D6 | 2 | 6 |
| Absolute | DEC $FFFF | $CE | 3 | 6 |
| Absolute,X | DEC $FFFF,X | $DE | 3 | 7 |
+----------------+-----------------------+---------+---------+----------+
For penalty cycles on the 65816, check the desired addressing mode.
65816 Extensions:
+----------------+-----------------------+---------+---------+----------+
| Addressing Mode| Assembly Language Form| OP CODE |No. Bytes|No. Cycles|
+----------------+-----------------------+---------+---------+----------+
| Implied | DEC | $3A | 1 | 2 |
+----------------+-----------------------+---------+---------+----------+
What it does: Reduces the value of a byte in memory by 1. The N and Z flags are affected.
Major uses: A useful alternative to SBC when you are reducing the value of a memory address. DEC is simpler and shorter than SBC, and although DEC doesn't affect the C flag, you can still decrement double-byte numbers (see "Decrement Double-Byte Numbers" in Appendix D).
The other main use for DEC is to control a memory index when the X and Y Registers are too busy to provide this service. For example, you could define, say, address $505 as a counter for a loop structure. Then: LOOP STA $8000:DEC $505:BEQ ENDJMP LOOP. This structure would continue storing A into $8000 until address $505 was decremented down to zero. This imitates DEX or DEY and allows you to set up as many nested loop structures (loops within loops) as you wish.