Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - Parity flag for zero result

Reply to topic
Author Message
  • Joined: 14 Aug 2000
  • Posts: 517
  • Location: Adelaide, Australia
Reply with quote
Parity flag for zero result
Post Posted: Sun May 12, 2019 4:23 am
Does anyone know, for certain, not just theory, if a zero result from a logical op is odd or even parity to the Z80?

In have the following code where I want the function called if the state is 1 or 2 and not 0 or 3. A Call if Parity Odd will take care of this nicely because 1 and 2 have odd parity and 3 has even parity and, in theory, so does 0. But I haven't found a definite answer.


LD HL,StateVariable
LD A,(HL)
AND $03
CALL PO,Function
  View user's profile Send private message
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 12966
  • Location: London
Reply with quote
Post Posted: Sun May 12, 2019 8:17 am
Parity is just the xor of all bits, so 0 has even parity (0). Alternatively, it's the count of set bits, and 1 - so still 0.

Having said that, making it dumb and explicit in the code may be better unless this is really so performance critical. Else, a big fat comment is in order to explain why.
  View user's profile Send private message Visit poster's website
  • Joined: 14 Aug 2000
  • Posts: 517
  • Location: Adelaide, Australia
Reply with quote
Parity flag for zero result
Post Posted: Sun May 12, 2019 11:40 am
Great, thanks Maxim.

Yes I have gone the way of the big fat comment, because the logic is not immediately obvious.
  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!