0

I want to know how to count the 1's in a result to know the parity flag in assembly.

For example:

MOV AL, 0xFF   
MOV BL, 0x01  
ADD AL, BL

So the answer here in bits is 1 0000 0000, but in my professor's reviewer the parity flag = 1 so i assume that the carry out flag is counted too for parity flag? Am i correct or is my reviewer wrong?

And also, the overflow flag = 0? Why is that?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 3
    please specify target platform. There's no general consensus across all CPU types, how to report parity (if at all)... from instructions it looks as x86, where parity rules are quite specific, but in your case final result is: AL=0, CF=1, PF=1 (that means "even"), ZF=1, SF=0, OF=0 (writing them from head, so I may have went wrong with OF ... tried in TD.exe, indeed OF=0, and there's the "auxiliary carry", set to 1 too) (carry does NOT count for parity) – Ped7g Feb 20 '19 at 12:32
  • 4
    `OF` is signed overflow and you have just done `-1 + 1 = 0` which does not produce signed overflow. – Jester Feb 20 '19 at 12:34
  • the carry in to the msbit and the carry out bits match so no signed overflow. another way to see it is if the two msbits are the same and the carry out is different then signed overflow. your msbits are not the same so you cannot have a signed overflow. – old_timer Feb 20 '19 at 13:21
  • You can also do an add carry to 0 to put the carry bit back into a register. – Michael Dorgan Feb 20 '19 at 19:15

0 Answers0