Hi

" Parity is whether the number of 1 bits in a byte (or word) is
even or odd. The 8086 sets the parity flag after most arithmetic
and all logical operations. If parity is even, the flag is 1, if
parity is odd, the flag is 0.
"

I assume this is still true with 32-bit registers.
Then, why does my code fail ? What did I misunderstood ? Tested under Ollydbg 1.09

mov eax,0FFFF7D01h
and eax,0f0f0f0fh ;so eax has 12 1-bit
setp bl ;PF=0,BL=0
mov ,bl
mov eax,0FFFF7D01h
and eax,f0f0f0f0h ;so eax has 11 1-bit
setp bl ;PF=1,BL=1
mov ,bl
mov eax,0F9FFFFFFh
and eax,0f0f0f0fh ;so eax has 14 1-bit
setp bl ;PF=1,BL=1 ???
mov ,bl
mov eax,0F9FFFFFFh
and eax,0f0f0f0fh ;so eax has 16 1-bit
setp bl ;PF=1,BL=1 ???
mov ,bl


Thanks
Posted on 2003-02-25 07:07:44 by valy
The parity flag is set on a byte only, so if you use it to check eax, it only checks al
Posted on 2003-02-25 17:17:20 by Joshua
:mad: It is annoying. Thanks Joshua.

Then I should use something like this :

Mparity32get ARG1,ARG2,ARG3
mov ARG2,ARG1
bswap ARG1
xor ARG1,ARG2
mov ARG2,ARG1
shr ARG2,8
xor ARG1,ARG2
setp ARG3
ENDM
.
.
.
Mparity32get eax,ebx,bl

which is *much* longer :(

Posted on 2003-02-26 06:27:18 by valy
You can do it 2 steps shorter:


;if eax has parity
mov ecx,eax
bswap eax
xor eax,ecx
xor al,ah
setp bl
Posted on 2003-02-28 16:00:47 by The Svin