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:

    I would rather not see such winds subside, which carry your slow ship away, although they leave me, cast down, on an empty shore, often, with clenched hand, calling you cruel.
    Propertius Sextus (c. 50–16 B.C.)

    —Here, the flag snaps in the glare and silence
    Of the unbroken ice. I stand here,
    The dogs bark, my beard is black, and I stare
    At the North Pole. . .
    And now what? Why, go back.

    Turn as I please, my step is to the south.
    Randall Jarrell (1914–1965)

    The human species, according to the best theory I can form of it, is composed of two distinct races, the men who borrow and the men who lend.
    Charles Lamb (1775–1834)