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:

    He [Roosevelt] has made some speeches that indicate that he is going quite beyond anything that he advocated when he was in the White House, and has proposed a program which is absolutely impossible to carry out except by a revision of the Constitution.
    William Howard Taft (1857–1930)

    Hath not the morning dawned with added light?
    And shall not evening call another star
    Out of the infinite regions of the night,
    To mark this day in Heaven? At last, we are
    A nation among nations; and the world
    Shall soon behold in many a distant port
    Another flag unfurled!
    Henry Timrod (1828–1867)

    Ellen, I was crazy to read your book; but I never found anybody I could borrow it from!
    Anonymous Woman (c. 1870–?)