Shop OBEX P1 Docs P2 Docs Learn Events
What is parity for PASM commands... — Parallax Forums

What is parity for PASM commands...

Hi,

Simple question:

I'm looking at the p8x32A data-sheet, and noticing several commands set the carry bit to the so called "parity" of the result.
But the data sheet doesn't specify if that is even or odd parity.
So, if I have a command that tests a single bit: test ina,#4 wz,wc
The zero and carry bits are going to be set based on the value of bit number 2 of the input port.

example: if ina was equal to 7, executing the example command would cause the zero bit to be cleared.
But what would it do for the carry bit? set or cleared?

Thanks.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2015-10-16 17:27
    The parity is the sum of the individual bits of the 32-bit word modulo 2. The carry bit is effectively set to the odd parity.

    It turns out your example is problematic in that INA is a read-only register that appears in the destination address field. The TEST instruction is actually done between the "shadow RAM" location at the same address as INA, not the input register itself. What you want to do is: " TEST conFour,INA WZ,WC" where conFour is a constant with the value 4. In other words you'd have: "conFour LONG 4" somewhere after your code.

    In that case, the TEST does a logical and of 7 with 4 with the result being 4. This is nonzero so Z is cleared to 0. The parity of the result is 1 (or odd) so C is set to 1.
Sign In or Register to comment.