It is currently Thu Oct 19, 2017 3:01 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sun Jul 30, 2017 3:00 pm 
Offline

Joined: Tue Jul 01, 2014 4:02 pm
Posts: 254
Alright, so...this seems like it should be simpler than I'm making it. I'm probably going to botch the explanation here, but hopefully you guys will be able to decode what I mean.

I had a signed comparison so that I could evaluate for a negative number (checking the value of VAR to see if it is negative...this value has already been determined in a different part of code, this is just checking to see its value - so for instance, at this moment I might have "-27" as a signed value during the check...this isn't the moment where I'm mathing to GET "-27" so there is no simple matter of checking the carry). However, as it turned out I needed more than 128 possible positive values, so BPL/BMI that I was using for this turned out to not be a good evaluation method.

So I played around with BCC/BCS methods instead, but of course the problem is... the math is done in a different part of code to find out the value of VAR, so it's not just a matter of checking the carry in a resulting compare. At this point, if I want more than 128 "positive values", I'd have to evaluate it unsigned...but I can't really do that if I want more than 128 values in the positive.

The only way I could think to do this is kind of wonky - to continue using signed values, but *sacrifice* the upper most possible values. I could determine if it's -16 through -1, and if it is, treat it as negative. If it's either less than -16 as a signed number, or 0 and higher, i'd evaluate it as positive. That would essentially give me the ability to compare 0-240 as *positive* and be able to still have a negative value of down to -16...

It just seems...unnecessarily convoluted. Anyhow - that's my thought with how to approach it, but I figured I'd ask if there are any other thoughts on possible approaches to this?


Top
 Profile  
 
PostPosted: Sun Jul 30, 2017 3:09 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5718
Location: Canada
Couldn't you just add 16 to the number before doing an unsigned comparison then?


Top
 Profile  
 
PostPosted: Sun Jul 30, 2017 3:11 pm 
Offline

Joined: Tue Jul 01, 2014 4:02 pm
Posts: 254
Sure, or that. Same concept, more easily stated. I was just wondering if there was some other neat trick I might not be thinking about.


Top
 Profile  
 
PostPosted: Sun Jul 30, 2017 5:50 pm 
Online
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10063
Location: Rio de Janeiro - Brazil
You can use 16-bit variables and extend your signed range to -32768..32767. You can test bit 15 to tell whether the number is negative. But if 8-bits are enough except for detecting results below 0, extending the math to 16-bit sounds a bit like overkill.

You say you can't use the carry flag because the test is done in a difference place than the operation that makes the number negative, but have you thought about saving the carry flag right after the operation and test it later?

You can use PHP and PLP to save and restore all status flags, including the carry. If using the stack is troublesome for some reason (due to using subroutines, branches that might skip over the stack pop'ing, etc.), you can just shift the carry into a variable and shift it back out when you need to test it:

Code:
  ;(operation here)
  sta Result
  rol CarryBackup

  ;(lots of other code here)

  lsr CarryBackup
  bcc NegativeResult


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: tokumaru and 5 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:  
Powered by phpBB® Forum Software © phpBB Group