DEC
From C64-Wiki
Jump to navigationJump to search
DEC (short for "DECrease") is the mnemonic for a machine language instruction which decrements the numerical value of the contents of the address specified, by one, and "wraps over" if the value goes below the numerical limits of a byte.
- If the byte in question is taken as an unsigned integer, DEC "counts down" from 255 thru 0/$FF thru $0. If a byte already containing the value 0/$0 is DECremented, it "wraps over" to the value 255/$FF.
- If the byte is taken as a signed integer, DEC will "count down" from +127 thru −128, or +$7F thru −$80. If a byte already holding the value −128/−$80 is DECremented, it "wraps over" to the value +127/$7F.
Addressing modes[edit | edit source]
Opcode | Addressing mode |
Assembler format |
Length in bytes |
Number of cycles | |
Dec | Hex | ||||
206 | CE | Absolute | DEC nnnn | 3 | 6 |
222 | DE | Absolute,X | DEC nnnn,X | 3 | 7 |
198 | C6 | Zeropage | DEC nn | 2 | 5 |
214 | D6 | Zeropage,X | DEC nn,X | 2 | 6 |
DEC supports the four different addressing modes shown in the table at right. In the assembler formats listed, nn represents a single-byte (8-bit) figure, and nnnn is a two-byte (16-bit) address.
Although DEC does not support indexed-indirect and indirect-indexed addressing modes, DCP can be used to effectively implement these modes for DEC.
CPU flags[edit | edit source]
DEC affects 2 of the CPU's status flags:
- The negative status flag is set if the result is negative, i.e. has its most significant bit set.
- The zero flag is set if the result is zero, or cleared if it is non-zero.