What is the addressing mode of this opcode?
Posted: Fri Mar 02, 2018 12:12 pm
...by which I mean, given an opcode, what's the easiest way to find out the addressing mode?
The context is that in the Cowgol code generator I want to be able to look at an opcode byte and tell what the parameters are (so I know how to emit it, etc).
The easiest way to do this is just to use a lookup table, but that would be 256 bytes. The instruction set is pretty regular, and it occurs to me that I could probably come up with a set of rules that would have the same effect but be shorter (e.g. 'if the low nibble of 1 then it's one-byte indirect, either (zp,X) or (zp),Y'). But it's not entirely regular, with the occasional outlier like JMP (abs) wedged into the instruction set in places which don't map.
So I'd much rather use someone else's algorithm rather than try to come up with my own, if possible. Has this been done?
(I'm only interested in classic 6502 opcodes and don't care what the algorithm makes of undefined opcodes, which should make things simpler.)
The context is that in the Cowgol code generator I want to be able to look at an opcode byte and tell what the parameters are (so I know how to emit it, etc).
The easiest way to do this is just to use a lookup table, but that would be 256 bytes. The instruction set is pretty regular, and it occurs to me that I could probably come up with a set of rules that would have the same effect but be shorter (e.g. 'if the low nibble of 1 then it's one-byte indirect, either (zp,X) or (zp),Y'). But it's not entirely regular, with the occasional outlier like JMP (abs) wedged into the instruction set in places which don't map.
So I'd much rather use someone else's algorithm rather than try to come up with my own, if possible. Has this been done?
(I'm only interested in classic 6502 opcodes and don't care what the algorithm makes of undefined opcodes, which should make things simpler.)