Carry Flag - Carry Flag Vs. Borrow Flag

Carry Flag Vs. Borrow Flag

While the carry flag is well-defined for addition, there are two possible ways to use the carry flag for subtractive operations.

One uses the bit as a borrow flag, setting it if a<b when computing ab, and a borrow must be performed. A subtract with borrow (SBB) instruction will compute abC = a−(b+C), while a subtract without borrow (SUB) acts as if the borrow bit were clear. The 8080, Z80, x86 and 68k families (among others) use a borrow bit.

The other takes advantage of the identity that −x = not(x)+1 and computes ab as a+not(b)+1. The carry flag is set according to this addition, and subtract with carry computes a+not(b)+C, while subtract without carry acts as if the carry bit were set. The 6502 and PowerPC processors use this convention. The 6502 is a particularly well-known example because it does not have a subtract without carry operation, so software must ensure that the carry flag is set before every subtract operation where a borrow is not required.

The modern convention is to refer to the first alternative as a "borrow bit", while the second is called a "carry bit". However, there are exceptions in both directions; the VAX and NS320xx architectures use the borrow bit convention, but call their abC operation "subtract with carry" (SBWC). PA-RISC uses a carry bit convention, but calls its a+not(b)+C operation "subtract with borrow" (SUBB).

Read more about this topic:  Carry Flag

Famous quotes containing the words carry, flag and/or borrow:

    They have given us into the hand of new unhappy lords,
    Lords without anger and honour, who dare not carry their swords.
    They fight by shuffling papers; they have bright dead alien eyes;
    They look at our labour and laughter as a tired man looks at flies.
    Gilbert Keith Chesterton (1874–1936)

    There’s an enduring American compulsion to be on the side of the angels. Expediency alone has never been an adequate American reason for doing anything. When actions are judged, they go before the bar of God, where Mom and the Flag closely flank His presence.
    Jonathan Raban (b. 1942)

    Acquaintance. A person whom we know well enough to borrow from, but not well enough to lend to.
    Ambrose Bierce (1842–1914)