The carry flag is affected by the result of most arithmetic (and typically several bitwise) instructions and is also used as an input to many of them. Several of these instructions have two forms which either read or ignore the carry. In
assembly languages these instructions are represented by
mnemonics such as ADD/SUB, ADC/SBC (ADD/SUB including carry), SHL/SHR (
bit shifts), ROL/ROR (bit rotates), RCR/RCL (rotate through carry), and so on. The use of the carry flag in this manner enables multi-
word add, subtract, shift, and rotate operations. Consider adding 255 + 255 (11111111 + 11111111). The result should be 510, which is the 9-bit value 111111110 in binary. However, if using an
8-bit register, only the 8 least significant bits will be stored in the register, binary 11111110 (decimal 254 decimal). Since there is carry out of bit 7 (the eighth bit), the carry is set, indicating that the result needs 9 bits. The valid 9-bit result is the concatenation of the carry flag with the result. The other common ALU
status register bits will be Sign_Flag set, Zero_flag clear, and Overflow_Flag clear. If 11111111 represents two's complement signed integer −1 (x86 instruction ADD al,-1), then the interpretation of the result is −2 because Overflow_Flag is clear, and Carry_Flag is ignored. The sign of the result is negative, because Sign_Flag is set. 11111110 is the two's complement form of signed integer −2. If 11111111 represents unsigned integer binary number 255 (x86 instruction ADD al,255), then the interpretation of the result would be 254, which is not correct, because the most significant bit of the result went into the Carry_Flag, which therefore cannot be ignored. The Overflow_Flag and the Sign_Flag are ignored. Another example may be an 8-bit
register with the bit pattern 01010101 and the carry flag set; if we execute a
rotate left through carry instruction, the result would be 10101011 with the carry flag cleared because the most significant bit (bit 7) was rotated into the carry while the carry was rotated into the least significant bit (bit 0). Most microprocessors, all the way back to the
Intel 4004 and
Intel 8008, have specific instructions to set and reset the carry flag. One exception was the
Intel 8080 (and its derivative
Z80), which did not include an explicit reset carry opcode, as the operation could be performed by any of the bitwise logical instructions (AND, OR, XOR), which cleared the carry flag. The carry flag is also often used following comparison instructions, which are typically implemented as subtraction operations, to allow a decision to be made about which of the two compared values is less than (or greater or equal to) the other. Branch instructions which examine the carry flag are often represented by
mnemonics such as BCC and BCS to branch if the carry is clear, or branch if the carry is set respectively. When used in this way the carry flag provides a mechanism for comparing the values as unsigned integers. This is in contrast to the
overflow flag which provides a mechanism for comparing the values as signed integer values. == Vs. borrow flag ==