flagssubtraction8085carryflag

Is carry flag complemented when subtrahend is converted into 2's complement in 8085 microprocessor?


I was studying from a web course and found an example in which subtraction operation was explained. In that example,

A= A5H, B= 9BH

and operation SUB B was executed.

As the subtraction operation in 8085 microprocessor is carried out by converting subtrahend into 2's complement and then adding it to minuend, the answer thus obtained was A= (0000 1010)2(see figure)

As it is clearly visible that a carry is produced after the operation, so the CY flag, i.e., carry flag must be SET. But they explained it as under:

"CY bit seems to be ‘1’. But it is complemented and then stored. Therefore, CY bit is stored as ‘0’."

I didn't understand that why carry flag is to be complimented? Is it because the subtrahend is converted into 2's complement or anything else?


Solution

  • Indirectly, yes.

    In order to subtract with a 'borrow' status result as 808x architecture requires, you add the complement of the subtrahend, AND complement the carry out from the ALU to get the 'borrow' bit. Thus you complement carry for effectively the same reason you complemented the subtrahend, but not directly because you did so.

    Some CPUs instead have a 'carry/NOT borrow' status which uses the un-complemented carry logic. See https://en.wikipedia.org/wiki/Carry_flag#Carry_flag_vs._borrow_flag .