In 8085,we've learned that the carry flag is SET,when the content of the memory exceeds that of the accumulator and that,comparison is always with respect to the accumulator.But in 8086,comparison doesn't always take place with respect to the accumulator.So how is the carry flag SET or RESET in this case?
Electronic – Doubt regarding the CMP instruction of the 8086 microprocessor
microprocessor
Related Topic
- Electronic – Memory timing values for microprocessor (8086)
- Electrical – Invalid opcodes
- Electrical – Doubt regarding ADD instruction of the 8086 microprocessor
- Electronic – 8085 MPU; Stepping through an instruction (Timing diagrams)
- Electronic – Accessing odd address memory locations in 8086
- Electrical – DAA operation in 8085 microprocessor
Best Answer
The cmp (compare) instruction is identical to the sub (subtract without borrow) instruction with one important difference - it does not store the difference back into the destination operand.
The syntax of a subtract instruction is:
The generic form of the instruction is:
so dest is a bit of a misnomer in this case, since nothing is stored.
The carry flag C is set after a cmp operation if subtracting src from dest requires a borrow. This occurs only when dest is less than src where dest and src are both unsigned values. For signed operands, the C flag has no meaning.
The various forms are (in each case, the first op is dest, the second is src):
To be complete, here is the rundown on the other flags:
The zero flag Z is set if and only if dest = src.
The sign S and overflow O flags are only vald if the operands are considered signed (i.e., just the opposite of the C flag).
For signed comparisons, the S (sign) and O (overflow) flags, taken together, have the following meaning:
If ((S=0) and (O=1)) or ((S=1) and (O=0)) then dest < src
If ((S=0) and (O=0)) or ((S=1) and (O=1)) then dest >= src