Selasa, 10 Juli 2018

Sponsored Links

overflow flag - YouTube
src: i.ytimg.com

In the computer processor, the carry flag (usually indicated as the C flag) is a single bit in the system state (flag) register used to indicate when arithmetic carrying or borrowing has been generated from the position bit ALU is the most significant. The carry flag allows numbers larger than a single ALU width to be added/subtracted by bringing (adding) binary digits from partial addition/subtraction to the most significant bit positions of a more significant word. It's also used to extend bits and shifts rotate the same way on multiple processors (sometimes done via the X flag). For subtractive operations, two conventions (opposites) are used because most machines set a carry flag when borrowing multiple machines (such as 6502 and PIC) instead of reset flag carry on lending (and vice versa).


Video Carry flag



Usage

The carry flag is affected by arithmetic instruction results (and usually some bits) and is also used as input for many of them. Some of these instructions have two forms that either read or ignore the carry. In assembly language these instructions are represented by mnemonics such as ADD/SUB, ADC/SBC (ADD/SUB including carry), SHL/SHR (bit shift), ROL/ROR (bit rotate), RCR/RCL (rotate through carry), and so on. The use of carry flags in this way allows multi-word add, subtract, shift, and rotate operations.

An example is what happens if someone adds 255 and 255 using an 8-bit register. The result should be 510 which is 1_1111_1110 in binary, requires 9 bits. The 8 most significant bits that are always stored in registers are 1111_1110 binary (254 decimal) but since there is 7 bit work, the carry is set, indicating that the result requires 9 bits. A valid 9-bit result is a combination of a carry flag with the result. Note that in the 8-bit complementary interpretation , this operation is -1 -1 and returns the correct result -2, without spillover, even if the carry is ignored.

Another example might be an 8-bit register with bit pattern 0101_0101 and set of carrier flags; if we execute the rotate left through carry instruction, the result will be 1010_1011 with the carry flag cleared because the most significant bit (bit 7) is rotated into the carry while the carry is rotated to the least significant bit (bit 0).

Early microprocessors Intel 4004 and Intel 8008 have specific instructions for explicitly setting and reset carry flags. However, then Intel 8080 (and Z80) does not include an explicit carry-back opcode because this can be done equally quickly through one of the instruction bitwise AND, OR or XOR (which does not use carry flags).

The flags carry are also often used following the comparison instructions, which are usually carried out by subtractive operations, to allow decisions made about which of the two comparable values ​​are lower than (or greater than or equal to) others. The branch instructions checking the carrier flag are often represented by mnemonics such as BCC and BCS to branches if carry is clear, or branches if carry are set respectively. When used in this way the carry flag provides a mechanism for comparing values ​​as an unsigned integer. This is in contrast to the overflow flag that provides a mechanism for comparing values ​​as signed integer values.

Maps Carry flag



Carrying a flag vs. borrow flag

While carry flags are well defined for additions, there are two common ways to use carry flags for subtraction operations.

The first uses bits as lending flags, setting them if a & lt; b when calculating a - b , and a loan must be made. If a > = b , slightly removed. The subtraction with a loan (SBB) command will calculate a - b - C = a - ( b C ), while reductions without borrowing (SUB) act as if it were a bit obvious. Families 8080, Z80, 8051, x86 and 68k (among others) use the loan.

The second takes advantage of the identities that - x = no x ) 1 and calculates a - b like < i> a not ( b ) 1. The carry flag is set according to this addition, and subtract by bringing counting a not ( b ) C , while subtracting without carrying acts as if carrying little is set. The result is that the carry bit is set if a = b , and explain if a & lt; b . Processor Systems/360, 6502, MSP430, ARM and PowerPC use this convention. The 6502 is a well-known example of having no reduction without carry operations, so programmers must ensure that carry flags are set before any subtraction operation where borrowing is not required.

Most commonly, the first alternative is referred to as "subtract by borrow", while the second is called "subtract by bringing". However, there are exceptions in both directions; the VAX, NS320xx, and Atmel AVR architectures use the loan convention, but call a - b - C their operations "subtract by bringing" ( SBWC , SUBC and SBC ). PA-RISC and PICmicro architectures use carry-bit conventions, but call a not ( b ) operations they "subtract by borrowing" ( SUBB and SUBWFB ).

The 8-bit ST6/ST7 microcontroller is probably the most confusing of all. Although they do not perform "carry less" instructions, they have carry bits set by reduction instructions, and conventions depend on the processor model. ST60 processors use "carry" convention, while ST62 and ST63 processors use "borrow" conventions.

18. Auxiliary flag - YouTube
src: i.ytimg.com


See also

  • Binary arithmetic
  • The Half-Carry Flag
  • List status

1 Carry Flag - YouTube
src: i.ytimg.com


References


16. Overflow flag - YouTube
src: i.ytimg.com


External links

  • Bringing Flags and Overflow in binary arithmetic
  • Carry Bit: How does it work?

Source of the article : Wikipedia

Comments
0 Comments