assemblyparity8085

assembly lang 8085 .. how to find even/odd parity


I have the following code to count the number of 1s and save it to reg B. I need to modify it to find if the parity is even or odd...

LXI H, var1
MVI B, 00H
MVI D, 00H
MVI C, 08H
MOV A, M

LOOP: RAR
JNC SKIP
INR B
SKIP: DCR C
JNZ LOOP

HLT

var1: db 72

Solution

  • An even parity means that there's an even number of bits set in an octet. According to this brief introduction to Intel 8085 architecture:

    Flag is an 8-bit register containing 5 1-bit flags:
    - Sign - set if the most significant bit of the result is set.
    - Zero - set if the result is zero.
    - Auxiliary carry - set if there was a carry out from bit 3 to bit 4 of the result.
    - Parity - set if the parity (the number of set bits in the result) is even.
    - Carry - set if there was a carry during addition, or borrow during subtraction/comparison.

    The parity flag can be most easily tested with conditional branches (link to source)

    JPE label;   // Jump if parity is Even 
    JPO label;   // or jump if parity is Odd
    

    The flag is set by most arithmetic and logical instructions that deal with a single output registers. Counter-examples are MOV, and CMP, which doesn't store a result. Arithmetic operations (INX, DEX etc.) that modify a register pair in turn do not have an unambiguous result.