I've been reading around and with the 8086 Instruction Set, it says that a CMP (compare) can set the Carry Flag. I understand that a compare subtracts two operands but I was wondering if anyone can provide an example when that is the case.
I just can't grasp the idea of adding a number and a negative number will set the carry flag. I've read into the borrow flag but I just needed an example to clarify my understanding of a compare instruction.
Also, I understand that if 3 - 5 = -2 would set the negative flag... when is carry set?
CMP and TEST instructions affect flags only and do not store a result (these instruction are used to make decisions during program execution). These instructions affect these flags only: CF, ZF, SF, OF, PF, AF.
The CMP instruction sets the flags as if it had performed subtraction on the operand. Subtracting 1000 from 1000 results in zero. A conditional jump instruction branches to a destination label when a flag condition is true.
The CMP instruction compares two operands. It is generally used in conditional execution. This instruction basically subtracts one operand from the other for comparing whether the operands are equal or not.
- The CMP instruction can be used to compare two 8-bit or two 16-bit numbers. - Whenever a compare operation is performed the result of such an operation reflects in one of the six status flags CF, AF, OF, PF, SF and ZF. -The CMP operation is also known as the subtraction method as it uses two`s complement for it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With