...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.)
What is the addressing mode of this opcode?
Re: What is the addressing mode of this opcode?
Of course I found this immediately after posting my message:
http://www.llx.com/~nparker/a2/opcodes.html
So, uh --- thanks, everyone!
http://www.llx.com/~nparker/a2/opcodes.html
So, uh --- thanks, everyone!
Re: What is the addressing mode of this opcode?
This fragment is from the Acorn Teletext VDU manual. It determines if an Op-Code is a single byte, 2-byte or 3-byte instruction. It only works for the NMOS instruction set and doesn't give any details of the addressing mode but somebody might find it useful.
Code: Select all
Enter with the Op-Code in A
CMP #$20 JSR is an anomaly and is done first
BEQ BYTE3
AND #$9F
BEQ BYTE1 binary OXX00000 is 1 byte
AND #$1D
CMP #$19
BEQ BYTE3 binary XXX110X1 is 3 bytes
AND #$0D
CMP #$08
BEQ BYTE1 binary XXXXX0X0 (now) is 1 byte
AND #$0C
CMP #$0C
BEQ BYTE3 binary XXXX11 XX is 3 bytes
If we get to here, it must be a 2-byte instruction
Shift to the left,
Shift to the right,
Mask in, Mask Out,
BYTE! BYTE! BYTE!
Shift to the right,
Mask in, Mask Out,
BYTE! BYTE! BYTE!
Re: What is the addressing mode of this opcode?
That's very nice!