Skip to main content
Commonmark migration
Source Link

The intermediate carry flag, or "adjust flag", or half-carry flag is used to facilitate binary-coded decimal (BCD) arithmetic, where each decimal digit of a number is represented as a nibble (a group of 4 bits). The range of valid values for each nibble is 0 to 9 (0000 to 1001). If, after an arithmetic operation, the result contains a "non-decimal" nibble (1010 to 1111), it can be deduced from its bit pattern that a correction is necessary. However, it might also be necessary even if both nibbles of the result look "decimal".

Here's an example (from Wikipedia) why the flag is needed:

Adding the BCD values 3916 and 4816 produces 8116. This result does not have a non-decimal low nibble, but it does cause a carry out of the least significant digit (lower four bits) into the most significant digit (upper four bits). This is indicated by the CPU setting the half-carry flag. This value must also be corrected, by adding 0616 to 8116 to produce a corrected BCD result of 8716.

 
  0011 1001   39
+ 0100 1000   48
-----------
  1000 0001   81, intermediate result
+      0110   06, adjustment
-----------
  1000 0111   87, adjusted result

The intermediate carry flag, or "adjust flag", or half-carry flag is used to facilitate binary-coded decimal (BCD) arithmetic, where each decimal digit of a number is represented as a nibble (a group of 4 bits). The range of valid values for each nibble is 0 to 9 (0000 to 1001). If, after an arithmetic operation, the result contains a "non-decimal" nibble (1010 to 1111), it can be deduced from its bit pattern that a correction is necessary. However, it might also be necessary even if both nibbles of the result look "decimal".

Here's an example (from Wikipedia) why the flag is needed:

Adding the BCD values 3916 and 4816 produces 8116. This result does not have a non-decimal low nibble, but it does cause a carry out of the least significant digit (lower four bits) into the most significant digit (upper four bits). This is indicated by the CPU setting the half-carry flag. This value must also be corrected, by adding 0616 to 8116 to produce a corrected BCD result of 8716.

 
  0011 1001   39
+ 0100 1000   48
-----------
  1000 0001   81, intermediate result
+      0110   06, adjustment
-----------
  1000 0111   87, adjusted result

The intermediate carry flag, or "adjust flag", or half-carry flag is used to facilitate binary-coded decimal (BCD) arithmetic, where each decimal digit of a number is represented as a nibble (a group of 4 bits). The range of valid values for each nibble is 0 to 9 (0000 to 1001). If, after an arithmetic operation, the result contains a "non-decimal" nibble (1010 to 1111), it can be deduced from its bit pattern that a correction is necessary. However, it might also be necessary even if both nibbles of the result look "decimal".

Here's an example (from Wikipedia) why the flag is needed:

Adding the BCD values 3916 and 4816 produces 8116. This result does not have a non-decimal low nibble, but it does cause a carry out of the least significant digit (lower four bits) into the most significant digit (upper four bits). This is indicated by the CPU setting the half-carry flag. This value must also be corrected, by adding 0616 to 8116 to produce a corrected BCD result of 8716.

  0011 1001   39
+ 0100 1000   48
-----------
  1000 0001   81, intermediate result
+      0110   06, adjustment
-----------
  1000 0111   87, adjusted result
added 15 characters in body
Source Link
Leo B.
  • 20.7k
  • 5
  • 50
  • 157

The intermediate carry flag, or "adjust flag", or half-carry flag is used to facilitate binary-coded decimal (BCD) arithmetic, where each decimal digit of a number is represented as a nibble (a group of 4 bits). The range of valid values for each nibble is 0 to 9 (0000 to 1001). If, after an arithmetic operation, the result contains a "non-decimal" nibble (1010 to 1111), it can be deduced from its bit pattern that a correction is necessary. However, it might also be necessary even if both nibbles of the result look "decimal".

Here's an example (from Wikipedia) why the flag is needed:

Adding the BCD values 3916 and 4816 produces 8116. This result does not have a non-decimal low nibble, but it does cause a carry out of the least significant digit (lower four bits) into the most significant digit (upper four bits). This is indicated by the CPU setting the half-carry flag. This value must also be corrected, by adding 0616 to 8116 to produce a corrected BCD result of 8716.

  0011 1001   39
+ 0100 1000   48
-----------
  1000 0001   81, intermediate result
+      0110   06, adjustment
-----------
  1000 0111   87, adjusted result

The intermediate carry flag, or "adjust flag", or half-carry flag is used to facilitate binary-coded decimal (BCD) arithmetic, where each decimal digit of a number is represented as a nibble (a group of 4 bits). The range of valid values for each nibble is 0 to 9 (0000 to 1001). If, after an arithmetic operation, the result contains a "non-decimal" nibble, it can be deduced from its bit pattern that a correction is necessary. However, it might also be necessary even if both nibbles of the result look "decimal".

Here's an example (from Wikipedia) why the flag is needed:

Adding the BCD values 3916 and 4816 produces 8116. This result does not have a non-decimal low nibble, but it does cause a carry out of the least significant digit (lower four bits) into the most significant digit (upper four bits). This is indicated by the CPU setting the half-carry flag. This value must also be corrected, by adding 0616 to 8116 to produce a corrected BCD result of 8716.

  0011 1001   39
+ 0100 1000   48
-----------
  1000 0001   81, intermediate result
+      0110   06, adjustment
-----------
  1000 0111   87, adjusted result

The intermediate carry flag, or "adjust flag", or half-carry flag is used to facilitate binary-coded decimal (BCD) arithmetic, where each decimal digit of a number is represented as a nibble (a group of 4 bits). The range of valid values for each nibble is 0 to 9 (0000 to 1001). If, after an arithmetic operation, the result contains a "non-decimal" nibble (1010 to 1111), it can be deduced from its bit pattern that a correction is necessary. However, it might also be necessary even if both nibbles of the result look "decimal".

Here's an example (from Wikipedia) why the flag is needed:

Adding the BCD values 3916 and 4816 produces 8116. This result does not have a non-decimal low nibble, but it does cause a carry out of the least significant digit (lower four bits) into the most significant digit (upper four bits). This is indicated by the CPU setting the half-carry flag. This value must also be corrected, by adding 0616 to 8116 to produce a corrected BCD result of 8716.

  0011 1001   39
+ 0100 1000   48
-----------
  1000 0001   81, intermediate result
+      0110   06, adjustment
-----------
  1000 0111   87, adjusted result
Explained the BCD format.
Source Link
Leo B.
  • 20.7k
  • 5
  • 50
  • 157

The intermediate carry flag, or "adjust flag", or half-carry flag is used to facilitate binary-coded decimal (BCD) arithmetic, where each decimal digit of a number is represented as a nibble (a group of 4 bits). The range of valid values for each nibble is 0 to 9 (0000 to 1001). If, after an arithmetic operation, the result contains a "non-decimal" nibble, it can be deduced from its bit pattern that a correction is necessary. However, it might also be necessary even if both nibbles of the result look "decimal". 

Here's an example (from Wikipedia) why the flag is needed:

Adding the BCD values 3916 and 4816 produces 8116. This result does not have a non-decimal low nibble, but it does cause a carry out of the least significant digit (lower four bits) into the most significant digit (upper four bits). This is indicated by the CPU setting the half-carry flag. This value must also be corrected, by adding 0616 to 8116 to produce a corrected BCD result of 8716.

  0011 1001   39
+ 0100 1000   48
-----------
  1000 0001   81, intermediate result
+      0110   06, adjustment
-----------
  1000 0111   87, adjusted result

The intermediate carry flag, or "adjust flag", or half-carry flag is used to facilitate binary-coded decimal (BCD) arithmetic. Here's an example (from Wikipedia) why the flag is needed:

Adding the BCD values 3916 and 4816 produces 8116. This result does not have a non-decimal low nibble, but it does cause a carry out of the least significant digit (lower four bits) into the most significant digit (upper four bits). This is indicated by the CPU setting the half-carry flag. This value must also be corrected, by adding 0616 to 8116 to produce a corrected BCD result of 8716.

  0011 1001   39
+ 0100 1000   48
-----------
  1000 0001   81, intermediate result
+      0110   06, adjustment
-----------
  1000 0111   87, adjusted result

The intermediate carry flag, or "adjust flag", or half-carry flag is used to facilitate binary-coded decimal (BCD) arithmetic, where each decimal digit of a number is represented as a nibble (a group of 4 bits). The range of valid values for each nibble is 0 to 9 (0000 to 1001). If, after an arithmetic operation, the result contains a "non-decimal" nibble, it can be deduced from its bit pattern that a correction is necessary. However, it might also be necessary even if both nibbles of the result look "decimal". 

Here's an example (from Wikipedia) why the flag is needed:

Adding the BCD values 3916 and 4816 produces 8116. This result does not have a non-decimal low nibble, but it does cause a carry out of the least significant digit (lower four bits) into the most significant digit (upper four bits). This is indicated by the CPU setting the half-carry flag. This value must also be corrected, by adding 0616 to 8116 to produce a corrected BCD result of 8716.

  0011 1001   39
+ 0100 1000   48
-----------
  1000 0001   81, intermediate result
+      0110   06, adjustment
-----------
  1000 0111   87, adjusted result
Source Link
Leo B.
  • 20.7k
  • 5
  • 50
  • 157
Loading