“Assembly Language”, 3rd Edition by Wang Shuang
Chapter 11: Flag Registers
Checkpoint 11.2 (Page 219)
Write down the values of the flags ZF, PF, SF, CF, OF, etc., after executing each of the following instructions.
———————-Analysis Explanation
1. sub al, al
Final result is (al)=0H=00000000B, as an unsigned operation there is no carry or borrow, as a signed operation there is no overflow, the highest bit of the signed result is 0, so it is non-negative, the result is 0 so ZF=1, there are 0 bits that are 1 (0 is considered even) so PF=1.
2. mov al, 10H The transfer instruction does not affect the flag bits.
3. add al, 90H
Final result is (al)=A0H=10100000B, as an unsigned operation 16+144=160, the highest bit does not carry to a higher bit, as a signed operation 16-112=-96, it does not exceed the 8-bit signed range, so there is no overflow, as a signed number the highest bit is 1 indicating a negative number so SF=1, the result is not 0 so ZF=0, the number of 1 bits in the result is 2 which is even so PF=1.
4. mov al, 80H The transfer instruction does not affect the flag bits.
5. add al, 80H
The result is 256=100H=100000000B, since al is only 8 bits, the final result (al)=00000000B, as an unsigned operation 128+128=256 produces a carry, as a signed operation (-128)+(-128)=-256 has overflow, as a signed number the highest bit is 0 so SF=0, the final result is 0 so ZF=1, the number of 1 bits in the result is 0 which is even so PF=1.
6. mov al, 0FCH The transfer instruction does not affect the flag bits.
7. add al, 05H
As an unsigned operation 252+5=257 produces a carry, as a signed operation (-4)+5=1 has no overflow, as a signed number the highest bit is 0 so SF=0, the final result is not 0 so ZF=0, the number of 1 bits in the result is 1 which is odd so PF=0.
8. mov al, 7DH The transfer instruction does not affect the flag bits.
9. add al, 0BH
As an unsigned operation 125+11=136 has no carry, as a signed operation 125+11=136 exceeds the limit so it will overflow, as a signed number the highest bit is 1 so SF=1, the final result is not 0 so ZF=0, the number of 1 bits in the result is 2 which is even so PF=1.
Based on the above, the reference answers are:
