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:

    Though we travel the world over to find the beautiful, we must carry it with us, or we find it not.
    Ralph Waldo Emerson (1803–1882)

    Columbus stood in his age as the pioneer of progress and enlightenment. The system of universal education is in our age the most prominent and salutary feature of the spirit of enlightenment, and it is peculiarly appropriate that the schools be made by the people the center of the day’s demonstration. Let the national flag float over every schoolhouse in the country and the exercises be such as shall impress upon our youth the patriotic duties of American citizenship.
    Benjamin Harrison (1833–1901)

    If you must commit suicide ... always contrive to do it as decorously as possible; the decencies, whether of life or of death, should never be lost sight of.
    —George Borrow (1803–1881)