6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Oct 05, 2024 4:34 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Fri Mar 02, 2018 12:12 pm 
Offline
User avatar

Joined: Thu Oct 12, 2017 10:51 pm
Posts: 90
...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.)


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 02, 2018 1:20 pm 
Offline
User avatar

Joined: Thu Oct 12, 2017 10:51 pm
Posts: 90
Of course I found this immediately after posting my message:

http://www.llx.com/~nparker/a2/opcodes.html

So, uh --- thanks, everyone!


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 02, 2018 1:27 pm 
Offline
User avatar

Joined: Mon Dec 08, 2008 6:32 pm
Posts: 143
Location: Brighton, England
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:

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!


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 02, 2018 6:12 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10949
Location: England
That's very nice!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: