Introduction
An opcode byte is two nibbles: I (the high one) and N (the low one). The 1802 has no addressing modes in the usual sense: memory is addressed only through a register, the one the opcode names (N), or R(X), or R(P) for an immediate byte.
The formats
| Format | Opcodes | Bytes | Meaning of N |
|---|---|---|---|
| Register | 0N (N is not 0), 1N, 2N, 4N, 5N, 8N, 9N, AN, BN, DN, EN | 1 | The register: LDN INC DEC LDA STR GLO GHI PLO PHI SEP SEX. Opcode 00 is IDL. |
| Through R(X) | 60, 70 to 75, 77 to 7B, 7E, F0 to F7, FE | 1 | No operand: the memory byte is at R(X), or D alone is used. |
| Port | 61 to 67, 69 to 6F | 1 | The port number on the N lines: OUT 1 to 7, INP 1 to 7 (the low three bits). |
| Immediate | 7C, 7D, 7F, F8 to FD, FF | 2 | The following byte is the value. |
| Short branch | 30 to 3F | 2 | The following byte is the low byte of the target on a page; 38 (SKP) is a no-branch that skips it. |
| Long branch | C0 to C3, C8 to CB | 3 | The following two bytes are the target, high byte first; C8 (LSKP) never branches and skips them. |
| Long skip | C4 to C7, CC to CF | 1 | No operand: when the condition holds the next two bytes are skipped. C4 (NOP) never skips. |
| Reserved | 68 | 1 | Prefix of the CDP1804, CDP1805 and CDP1806 extended instructions. |
Short and long branches
A short branch replaces the low byte of the program counter with its operand when the condition holds; the high byte is unchanged. At that moment the program counter points at the operand byte, so the target is in the page of the operand byte: for an instruction at $12FE (operand at $12FF) the page is $12, for one at $12FF (operand at $1300) the page is $13. A long branch loads the whole 16-bit program counter. The conditions are the same set for both: always, Q, D = 0, DF, and (short only) the four external flags; each has its negation.
The names BPZ, BGE (for BDF) and BM, BL (for BNF) are used after a subtraction, when DF = 1 means no borrow (D is not less).
Skips
A long skip is a one-byte instruction that, when its condition holds, adds 2 to the program counter and so jumps over the next two bytes (an instruction of two bytes or the address of a long branch): LSNQ, LSNZ, LSNF, LSIE, LSQ, LSZ, LSDF. NOP is the long skip that never skips (it takes 3 machine cycles like them). LSKP (NLBR) always skips; it is encoded as a long branch that does not branch, so a listing shows it three bytes long. SKP (NBR) is the short version: it skips one byte. The disassembler shows the skip instruction itself and not the skipped bytes as dead code: it decodes the bytes after a conditional long skip as instructions as well, because whether they run depends on the data.
Not described
Known, not yet covered
- Reference: the extended instruction formats of the CDP1804 to CDP1806 (68 followed by an opcode and sometimes 16-bit operands).
Unknown
- Reference: whether a short branch whose operand is the last byte of a page behaves as the Wikipedia description says on every part (one core read differs).