0
votes

I didn't understand when the sign flag is set, and when the parity.

As I know, the sign flag indicates the sign of the result of an operation, 0 for positive numbers and 1 for negative numbers.

So why in the next code:

mov al, -5 
sub al, 124

The SF is zero? The result is negative number.

About the PF, Why in a and b, the PF is set?

a) sub al, al.

b) mov al, 127
   add al, 129
2

2 Answers

4
votes

The code

mov al, -5 
sub al, 124

calculates 256-5-124. It's 127 and it's positive number

Both sub al, al and 127+129 evaluates to 0, it has 0 bits set, and 0 is even value, so PF is set.

1
votes

the maximum number you can represent in 8 bits is 2^8-1 which is 255 thus because 127+129=256, al will hold 0, and flags: CF PF AF ZF IF would be set, PF is set as mentioned above - because PF is set if and only if the amount of bits set is even.