Introduction
The logic instructions combine the accumulator with a memory byte. The shifts and rotates move the bits of the accumulator or of a memory byte one place, passing the bit that falls off through the carry flag. Shifting left doubles a number and shifting right halves it (unsigned).
The instructions
Each form is written mode opcode, bytes, cycles; “+1 page” is one more cycle when an index crosses a page boundary.
| Instruction | Forms | What it does | Flags |
|---|---|---|---|
and | imm 29, 2, 2zp 25, 2, 3zp,X 35, 2, 4abs 2D, 3, 4abs,X 3D, 3, 4 +1 pageabs,Y 39, 3, 4 +1 page(zp,X) 21, 2, 6(zp),Y 31, 2, 5 +1 page(zp) 32, 2, 5 (65C02) | A = A AND memory. | N Z |
ora | imm 09, 2, 2zp 05, 2, 3zp,X 15, 2, 4abs 0D, 3, 4abs,X 1D, 3, 4 +1 pageabs,Y 19, 3, 4 +1 page(zp,X) 01, 2, 6(zp),Y 11, 2, 5 +1 page(zp) 12, 2, 5 (65C02) | A = A OR memory. | N Z |
eor | imm 49, 2, 2zp 45, 2, 3zp,X 55, 2, 4abs 4D, 3, 4abs,X 5D, 3, 4 +1 pageabs,Y 59, 3, 4 +1 page(zp,X) 41, 2, 6(zp),Y 51, 2, 5 +1 page(zp) 52, 2, 5 (65C02) | A = A exclusive-OR memory. | N Z |
bit | zp 24, 2, 3abs 2C, 3, 4imm 89, 2, 2 (65C02)zp,X 34, 2, 4 (65C02)abs,X 3C, 3, 4 +1 page (65C02) | Tests the bits of memory against A without changing either. Z is set when A AND memory is zero. N and V become copies of bits 7 and 6 of the memory byte, not of the result. The 65C02’s immediate form sets Z only. | N V Z (Z only for imm) |
asl | A 0A, 1, 2zp 06, 2, 5zp,X 16, 2, 6abs 0E, 3, 6abs,X 1E, 3, 7 (6 +1 page on the 65C02) | Shifts left: bit 7 goes to C and a zero comes in at bit 0. | N Z C |
lsr | A 4A, 1, 2zp 46, 2, 5zp,X 56, 2, 6abs 4E, 3, 6abs,X 5E, 3, 7 (6 +1 page on the 65C02) | Shifts right: bit 0 goes to C and a zero comes in at bit 7. N is always cleared. | N Z C |
rol | A 2A, 1, 2zp 26, 2, 5zp,X 36, 2, 6abs 2E, 3, 6abs,X 3E, 3, 7 (6 +1 page on the 65C02) | Rotates left through the carry: bit 7 goes to C and the old C comes in at bit 0. | N Z C |
ror | A 6A, 1, 2zp 66, 2, 5zp,X 76, 2, 6abs 6E, 3, 6abs,X 7E, 3, 7 (6 +1 page on the 65C02) | Rotates right through the carry: bit 0 goes to C and the old C comes in at bit 7. | N Z C |
Notes
- Memory shifts are read-modify-write. The NMOS 6502 writes the unchanged byte back before the changed one, which can matter on a hardware register.
- ROR on the earliest chips. The first production 6502s, before mid-1976, had no working ROR. Every later chip has it, and the explorer decodes it as an ordinary instruction.
- Bit set and reset. The 6502 has no instruction to set or clear one bit of a byte; ORA and AND with a mask do it. The 65C02 adds TSB and TRB, and the Rockwell and WDC chips RMB and SMB.