6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 11:25 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: CPU flags
PostPosted: Thu Jul 26, 2012 3:29 am 
Offline

Joined: Sun Nov 08, 2009 1:56 am
Posts: 411
Location: Minnesota
After lo these many years it finally dawned on me that a zero ("Z") flag is simply the inclusive-OR of all the register bits. Shortly thereafter another revelation: a parity ("P") flag is simply the exclusive-OR of all the register bits.

And then I wondered: did any computer ever have a flag based on the AND of all the register bits? This flag would be set if all the register bits are set, clear otherwise. Interpreted as a signed value: set if minus one, otherwise clear.

In the 65xx-world this would be a handy flag for all those countdown loops with a variable starting index that could be greater than 127. Then the last iteration wouldn't have to be handled as a special case. There are also plenty of occasions where a memory byte is set to $FF as a flag value; with an "M" ("A"? "O"?) flag simply loading the byte into a register would be enough to tell.

A quick Google search didn't turn anything up, but then I really don't have a proper name for what I'm looking for either. The real question I want to research is whether or not such a flag would be useful enough in general to implement. What has been the historical experience, if any? (The parity flag, for instance, has often been implemented but is sometimes questioned as to its usefulness).


Top
 Profile  
Reply with quote  
 Post subject: Re: CPU flags
PostPosted: Thu Jul 26, 2012 3:54 am 
Offline

Joined: Tue Jul 24, 2012 2:27 am
Posts: 679
If you want to branch until a value rolls past zero, a decrement which affects the carry flag would also work.

_________________
WFDis Interactive 6502 Disassembler
AcheronVM: A Reconfigurable 16-bit Virtual CPU for the 6502 Microprocessor


Top
 Profile  
Reply with quote  
 Post subject: Re: CPU flags
PostPosted: Thu Jul 26, 2012 5:19 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
Quote:
There are also plenty of occasions where a memory byte is set to $FF as a flag value; with an "M" ("A"? "O"?) flag simply loading the byte into a register would be enough to tell.

or BIT, so you don't even have to affect A, X, or Y. There might be a use for an F flag, but it's common to use a byte as a flag and anything but 0 means the flag is set, or at least anything negative. Without an STF (store FF) instruction which I would like to have, setting a flag can be a simple DEC, as long as you don't do it so many times that it again becomes 0 or even just positive. Use STZ to clear it. Then BIT, BMI/BPL for example tests it, without regard for what's in any of the registers, and without affecting them.

INC and DEC don't affect the carry flag.

_________________
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  
 Post subject: Re: CPU flags
PostPosted: Thu Jul 26, 2012 6:16 am 
Offline

Joined: Tue Jul 24, 2012 2:27 am
Posts: 679
GARTHWILSON wrote:
INC and DEC don't affect the carry flag.


Yes. Just to be clear, I was implying that instead of adding both a flag and 2 new branch instructions to the CPU, some of the functionality could be accomplished by adding something like dxc/dyc (decrement X/Y outputting carry), which would probably be a bit cheaper.

_________________
WFDis Interactive 6502 Disassembler
AcheronVM: A Reconfigurable 16-bit Virtual CPU for the 6502 Microprocessor


Top
 Profile  
Reply with quote  
 Post subject: Re: CPU flags
PostPosted: Thu Jul 26, 2012 5:20 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8513
Location: Midwestern USA
GARTHWILSON wrote:
Quote:
There are also plenty of occasions where a memory byte is set to $FF as a flag value; with an "M" ("A"? "O"?) flag simply loading the byte into a register would be enough to tell.

or BIT, so you don't even have to affect A, X, or Y. There might be a use for an F flag, but it's common to use a byte as a flag and anything but 0 means the flag is set, or at least anything negative. Without an STF (store FF) instruction which I would like to have, setting a flag can be a simple DEC, as long as you don't do it so many times that it again becomes 0 or even just positive. Use STZ to clear it. Then BIT, BMI/BPL for example tests it, without regard for what's in any of the registers, and without affecting them.

INC and DEC don't affect the carry flag.

You could also:

Code:
         sec
         ror flag

to set it and:

Code:
         bit flag

to test it.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 75 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: