0

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?

zubergu
  • 3,646
  • 3
  • 25
  • 38
Durgesh
  • 3
  • 3

1 Answers1

-1

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 .

dave_thompson_085
  • 34,712
  • 6
  • 50
  • 70
  • Okay. But even if the carry flag is complemented, the value of Auxiliary carry flag is different in this approach and the one in which subtrahend is directly subtracted from minuend. As the value of flag register by following complemented approach comes out to be (0000 0100), and if we follow direct approach by subtracting, then flag register value becomes (0001 0100) because the value of AC(Auxiliary carry flag) is 0 in previous case but while subtracting, lower nibble borrows from upper nibble which sets the AC flag. Can you explain why AC flag have different values for the same operation? – Durgesh Sep 30 '18 at 03:08
  • Sorry, I didn't do BCD back in the days of 808x and never bothered with AC. SO's 'related' https://stackoverflow.com/questions/50221505/auxiliary-carry-and-carry-flags-in-8085?rq=1 references a manual on bitsavers that indicates for SUB (and SBB) AC is the (unmodified) carry out of bit 3 for A plus complement-of-operand(-and-borrow). – dave_thompson_085 Oct 03 '18 at 00:48