Difference between revisions of "Carry Flag"

From Intellivision Wiki
Jump to: navigation, search
m
m (Protected "Carry Flag" ([edit=autoconfirmed] (indefinite) [move=autoconfirmed] (indefinite)))
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The Carry Flag (C), if set, indicates that the previous operation resulted in an unsigned integer overflow or underflow.  If clear, the previous operation did not result in an unsigned overflow or underflow. For example, during the process of arithmetic addition, an unsigned overflow can occur when two positive signed integers are added together and results in a third positive signed integer that is too large to contain in a single 16-bit register.<br/><br/>
+
[[Category:CP1610]]
 +
The Carry Flag (C), if set, indicates that the previous operation resulted in an unsigned integer overflow.  If clear, the previous operation did not result in an unsigned integer overflow.<br/><br/>
 +
 
 +
For unsigned addition, the Carry is set when the addition's result is larger than what would fit in a 16-bit register, and cleared otherwise.  For unsigned subtraction, the Carry is set whenever the minuend (the number being subtracted from) is greater than or equal to the subtrahend (the number being subtracted), and cleared otherwise.  (In essence, it indicates "Did Not Borrow.")  The Carry bit can be used in conjunction with ADCR to perform [[Extended Precision Arithmetic]].<br/><br/>
 +
 
 +
Since the CMP family of instructions compare numbers by subtracting them, one sometimes sees [[BC|Branch if Carry set]] described as an unsigned variation of "Branch if Greater-than or Equal"  (also BHIS: Branch if HIgher or Same), and [[BNC|Branch if No Carry set]] described as an unsigned variation of "Branch if Less-than" (also BLO:  Branch if LOwer).  The names BHIS and BLO come from the PDP-11.<br/><br/>
  
 
The behavior of the following opcodes is affected by the status of the Carry Flag.<br/>
 
The behavior of the following opcodes is affected by the status of the Carry Flag.<br/>
Line 33: Line 38:
 
[[CMP@]]<br/>
 
[[CMP@]]<br/>
 
<br/>
 
<br/>
* Indicates slight variation from normal Sign Flag behavior. See opcode documentation for more details.
+
* Indicates slight variation from normal Carry Flag behavior. See opcode documentation for more details.

Latest revision as of 08:12, 4 December 2010

The Carry Flag (C), if set, indicates that the previous operation resulted in an unsigned integer overflow. If clear, the previous operation did not result in an unsigned integer overflow.

For unsigned addition, the Carry is set when the addition's result is larger than what would fit in a 16-bit register, and cleared otherwise. For unsigned subtraction, the Carry is set whenever the minuend (the number being subtracted from) is greater than or equal to the subtrahend (the number being subtracted), and cleared otherwise. (In essence, it indicates "Did Not Borrow.") The Carry bit can be used in conjunction with ADCR to perform Extended Precision Arithmetic.

Since the CMP family of instructions compare numbers by subtracting them, one sometimes sees Branch if Carry set described as an unsigned variation of "Branch if Greater-than or Equal" (also BHIS: Branch if HIgher or Same), and Branch if No Carry set described as an unsigned variation of "Branch if Less-than" (also BLO: Branch if LOwer). The names BHIS and BLO come from the PDP-11.

The behavior of the following opcodes is affected by the status of the Carry Flag.

BC
BNC
BUSC
BESC
ADCR
GSWD
RLC*
RRC*

In addition to affecting the behavior of the opcodes above, the following opcodes affect the status of the Carry Flag.

CLRC
SETC
NEGR
ADCR
RSWD*
RRC*
RLC*
SARC*
SLLC*
ADDR
SUBR
CMPR
ADD
ADD@
SUB
SUB@
CMP
CMP@

  • Indicates slight variation from normal Carry Flag behavior. See opcode documentation for more details.