6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Wed May 08, 2024 5:51 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed Jun 15, 2022 3:09 am 
Offline

Joined: Sun Oct 03, 2021 2:17 am
Posts: 114
Today I had the thought (while programming the 65816), "sure would be nice if I could compare A with X easily." Is it possible to do this without storing one of the values to memory?

One silly way to do this is to decrement A and X together in a loop and see which one hits zero first. Is there a better way? (As for why I want to do this, I'm just curious about pushing this architecture to its limits:)


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 15, 2022 3:42 am 
Offline
User avatar

Joined: Fri Aug 03, 2018 8:52 am
Posts: 746
Location: Germany
doing it like that would work but be really really inefficient.
so there is no easy way to get around using memory
the easiest option would be to just push X onto the stack and compare A to it. as that won't require working with any specific address, just make sure both registers have the same width so the compare works correctly, and don't forget to pull X from the stack after your branching code

Code:
    PHX
    CMP 1,S
    <Branches go here>
    PLX


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 15, 2022 4:06 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8432
Location: Southern California
If they're both 8-bit, you could use the identity table suggested at https://www.nesdev.org/wiki/Identity_table (which I also incorporated in my article on self-modifying code at http://wilsonminesco.com/SelfModCode/); but that's not for 16-bit. With that, it becomes just
Code:
    CMP  table,X

The table can be used to derive many other non-existent instructions too.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 15, 2022 5:55 pm 
Offline

Joined: Sun Oct 03, 2021 2:17 am
Posts: 114
I like both of your methods because I don't have to make up an arbitrary temporary variable name. Thanks.


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 11 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: