6502 opcode bit pattern?

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
6502 opcode bit pattern?
by on (#57299)
I ve seen that the opcodes for the same instruction, for example:
Code:
// INC
   INC_Zero_page_E6      = 0xE6,
   INC_Zero_page_X_F6    = 0xF6,
   INC_Absolute_EE       = 0xEE,
   INC_Absolute_X_FE     = 0xFE,

Share some resemblance to one another. In this case Zero page modes have a 6 as low byte, while Absolute modes share an E. And non-indexed modes have an E as high byte, while X-indexed ones have an F.
This pattern may just be because the 6502 designer just laid them this way, but it also may be that there's a definite bit pattern there, one that could allow us to make some bitwise comparisons to the opcode to find out the addressing mode and what action to perform, independently, rather than making large switches or jump tables.

by on (#57301)
The 6502 wouldn't waste silicon for a table of arbitrary instruction mappings; they're all derived via patterns, as the interesting The 6502 Instruction Set Decoded page covers.