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 a−b, and a borrow must be performed. A subtract with borrow (SBB) instruction will compute a−b−C = 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 a−b 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 a−b−C 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 carry from my mothers womb
A fanatics heart.”
—William Butler Yeats (18651939)
“My dream is that as the years go by and the world knows more and more of America, it ... will turn to America for those moral inspirations that lie at the basis of all freedom ... that America will come into the full light of the day when all shall know that she puts human rights above all other rights, and that her flag is the flag not only of America but of humanity.”
—Woodrow Wilson (18561924)
“Acquaintance. A person whom we know well enough to borrow from, but not well enough to lend to.”
—Ambrose Bierce (18421914)