2
\$\begingroup\$

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?

\$\endgroup\$
3
\$\begingroup\$

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:

sub    dest, src        dest = dest - src and set flags

The generic form of the instruction is:

cmp     dest, src       perform dest - src and set flags

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):

cmp     reg, reg
cmp     reg, mem
cmp     mem, reg
cmp     reg, immediate data
cmp     mem, immediate data
cmp     eax/ax/al, immediate data 

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

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.