- Joined: 14 Aug 2000
- Posts: 742
- Location: Adelaide, Australia
|
Parity flag for zero result
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
|
- Site Admin
- Joined: 19 Oct 1999
- Posts: 14740
- Location: London
|
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.
|
- Joined: 14 Aug 2000
- Posts: 742
- Location: Adelaide, Australia
|
Parity flag for zero result
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.
|