GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||
GeezerVison is showing en.wikipedia.org — Carry flag - Wikipedia
In computer processors, the carry flag (usually indicated as the C flag) is a single bit in a system status register/flag register used to indicate when an arithmetic carry or borrow has been generated out of the most significant arithmetic logic unit (ALU) bit position. The carry flag enables numbers larger than a single ALU width to be added/subtracted by carrying (adding) a binary digit from a partial addition/subtraction to the least significant bit position of a more significant word.[1] This is typically programmed by the user of the processor on the assembly or machine code level, but can also happen internally in certain processors, via digital logic or microcode, where some processors have wider registers and arithmetic instructions than (combinatorial, or "physical") ALU.[2] It is also used to extend bit shifts and rotates in a similar manner on many processors (sometimes done via a dedicated flag). For subtractive operations, two (opposite) conventions are in common use: x86 processors set the carry flag on borrow, while the ARM clears the carry flag on borrow. UsesThe 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 Consider adding 255 + 255 ( The other common ALU status register bits will be If If Another example may be an 8-bit register with the bit pattern 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 Vs. borrow flag
While there is universal agreement on the meaning of the carry flag for addition, there are two opposite conventions in common use for its meaning during subtraction. The first uses the bit as a borrow flag, setting it if a<b when computing a−b, and a borrow must be performed. If a≥b, the bit is cleared. A subtract with borrow ( The second uses the identity that −x = (not x)+1 directly (i.e. without storing the carry bit inverted) 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 result is that the carry bit is set if a≥b, and clear if a<b. The System/360,[5] ARM, POWER/PowerPC, 6502, MSP430, COP8, Am29000, i960, and 88000 processors use this convention. The 6502 is a particularly well-known example because it does not have a subtract without carry operation, so programmers must ensure that the carry flag is set before every subtract operation where a borrow is not required.[6]
The processors listed above, which include the most popular microprocessors of the last few decades, call these operations "subtract with borrow" and "subtract with carry", respectively, but the nomenclature is far from consistent. The VAX, NS320xx, Fairchild Clipper and Atmel AVR architectures use the borrow bit convention, but call their a−b−C operation "subtract with carry" ( The H8, SPARC, and Motorola 6809 use other names. All use the borrow convention, but the H8 uses the mnemonic The ST6 8-bit microcontrollers are even less consistent. Although they do not have any sort of "subtract with carry" instruction, they do have a carry bit which is set by subtract instructions, and the convention depends on the processor model. The ST60 processor uses the "carry" convention, while the ST62 and ST63 processors use the "borrow" convention.[8] See alsoReferences
External linksHidden categories:
| |||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |