1

I'm was doing a manual operation with TEST (Parity flag operation), the problem it's that i can't get the right result, consider this:

ax = 256 = 0000 0001 0000 0000

so if i do:

test ah, 0x44

the PF flag operation should be:

0000 0000 = 0000 0001 & 0100 0100

PF = 0000 0000 XNOR 0000 0000

PF = 1111 1111?

I've followed the intel reference, according to this:

enter image description here

the question it's what i'm doing wrong?

MindLerp
  • 378
  • 1
  • 3
  • 15
  • If you are trying to set or reset PF flag you can do that with `lahf instruction` have a look at my answer https://stackoverflow.com/questions/41335653/how-to-check-if-the-cf-flag-is-1-in-emu8086/47373859#47373859 – Ahtisham Nov 21 '17 at 03:10
  • @Doda No, I want to do the formula manually, the problem it's that i'm not getting the same result than the program operation... – MindLerp Nov 21 '17 at 03:14
  • 1
    You're reading the reference incorrectly. First, the parameter is `TEMP[0:7]` but you are using `TEMP[15:8]`. Second, `BitwiseXNOR` has only one parameter, so it's not clear why you are calculating `0000 0000 XNOR 0000 0000` (especially since the result has 8 bits, but PF is only one bit). What `BitwiseXNOR` means is to XOR all the bits together, and then negate the result. – Raymond Chen Nov 21 '17 at 03:15
  • I don't understand Are you trying to set/reset PF flag ? – Ahtisham Nov 21 '17 at 03:15
  • @Raymond Chen Can you post a example or link example please? i can't find a operation done like example, and you mean `bit0 to bit7 xorged and then negated?` something like this `~(0^0^0^0^0^0^0)`? – MindLerp Nov 21 '17 at 03:23
  • @Doda No. just i want to do the operation manually... – MindLerp Nov 21 '17 at 03:25

1 Answers1

4

BitwiseXNOR is a horizontal XNOR of the bits, producing a single bit. Remember that PF is only 1 bit wide (a flag in EFLAGS), so it makes no sense to write PF=1111 1111.


It's the same parity calculation as always for instructions that "set flags according to the result", except that it's done on test's internal temporary result. (And as always, on the low 8 bits of it, regardless of operand size).

PF = 0 if the number of set bits is odd, PF = 1 if the number of set bits is even. So yes, the expression you posted in comments, ~(0^0^0^0^0^0^0^0) is correct.

See also:

  • https://en.wikipedia.org/wiki/Parity_flag
  • https://en.wikipedia.org/wiki/Parity_bit points out that parity is also the inverted (sum mod 2) of all the bits. (Because XOR is add-without-carry). Parity of an integer wider than 8 bits can be computed with popcnt eax, eax / not eax / and eax, 1. (Or use BMI andn eax, eax, ecx with ecx=1 set outside a loop to do the not-and part in one instruction.) Or just use the inverted parity value, where 1 = odd parity.

This answer has several examples of how PF is set from the horizontal-XOR of the bits in a result. In your case, the 8 bits are the AND result that test internally generates.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • yes, i had a bad logic about `BitwiseXNOR(Temporary[0:7]);` because that i'm was doing wrong... thank you... – MindLerp Nov 21 '17 at 06:43