It is currently Mon Oct 20, 2014 4:48 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Modulo 80
PostPosted: Sat Mar 31, 2012 11:04 am 
Offline
 Profile

Joined: Fri Nov 07, 2008 2:28 pm
Posts: 65
Has anybody got a good modulo 80?

I currently use this code but have just found the number can exceed 160 so it fails:

Code:
MACRO   WRAP80
      CMP   #80
      BCC   ok781
      SEC
      SBC   #80
.ok781:
ENDMACRO


I guess I could use a table but don't want to use up 256 bytes:

Code:
  TAX
  LDA mod80,X


- PJ


Top
 
 Post subject: Re: Modulo 80
PostPosted: Sat Mar 31, 2012 12:13 pm 
Offline
User avatar
 Profile

Joined: Sun Jun 28, 2009 11:37 pm
Posts: 55
You could just repeat the test a second time to catch values over 160.

The routine can also be optimised slightly by removing the redundant SEC:

Code:
MACRO   WRAP80
      CMP   #80
      BCC   ok781
      SBC   #80
      CMP   #80
      BCC   ok781
      SBC   #80
.ok781:
ENDMACRO


Top
 
 Post subject: Re: Modulo 80
PostPosted: Sat Mar 31, 2012 10:18 pm 
Offline
User avatar
 Profile

Joined: Mon Jan 07, 2008 6:46 pm
Posts: 380
Location: Málaga, Spain
In a similar vein is this, which will work for any value of A:

Code:
MACRO MOD80
    CMP #160
    BCC lessthan160
    SBC #160
    .lessthan160
    CMP #80
    BCC lessthan80
    SBC #80
    .lessthan80
ENDMACRO


Top
 
 Post subject: Re: Modulo 80
PostPosted: Sun Apr 01, 2012 3:03 pm 
Offline
 Profile

Joined: Fri Nov 07, 2008 2:28 pm
Posts: 65
Thanks for that - with the idea of testing it twice I've come up with this variation:

Code:
MACRO   WRAP80
.again:
      CMP   #80
      BCC   ok781
      SEC
      SBC   #80
      BNE   again
.ok781:
ENDMACRO


Top
 
 Post subject: Re: Modulo 80
PostPosted: Sun Apr 01, 2012 6:01 pm 
Offline
User avatar
 Profile

Joined: Mon Jan 07, 2008 6:46 pm
Posts: 380
Location: Málaga, Spain
You don't need the SEC, as C is obviously already set if it gets there. Other than that, yep, works a treat!


Top
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


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