Auxiliary carry flag

from Wikipedia, the free encyclopedia

The auxiliary carry flag , also known as the auxiliary carry flag (AF for short) is a term from computer science . This flag of the status register is set (AF: = 1) if an overflow has occurred in the lower nibble during an arithmetic operation . Otherwise it is deleted (AF: = 0).

use

The auxiliary carry flag is used for arithmetic operations in BCD format to indicate a possible position overflow.

In the case of binary addition or subtraction of binary- coded decimal digits (BCD format), an overflow is characterized by two possibilities:

  1. The lower 4 bits of the result do not represent a valid digit in BCD format . (1010 2 , 1011 2 , 1100 2 , 1101 2 , 1110 2 , 1111 2 ) .
  2. An overflow from the lower 4 bits to the upper 4 bits occurred during the arithmetic operation. (The auxiliary carry flag was set, AF = 1.)

The machine commands AAA (ASCII Adjust After Addition) and AAS (ASCII Adjust AL After Subtraction) react to the auxiliary carry flag.

In both cases, the commands AAA and AAS correct the lower 4 bits of the (AL) register and set the carry flag (CF: = 1) for further calculations.

AAA and AAS only consider the lower 4 bits of the (AL) register and delete the upper 4 bits. In this way, instead of the correct BCD-coded digits , the corresponding ASCII characters '0' - '9' can be loaded into the (AL) register , which have the signature 011 2 in the upper bits .

Examples

Addition 5 + 8 (The auxiliary carry flag is not set with this addition .)

MOV AL, 05h ; Load the number 5 into the AL register

ADD AL, 08h ; Add the number 8, AL = 13

AF: = 0, as there was no overflow in the nibble.

AAA ; The number 13 in the AL register is greater than 9, so there was a BCD overflow.

The result is corrected (AL: = 3) and the carry flag is set (CF = 1).

Addition 8 + 9 (The auxiliary carry flag is set with this addition.)

MOV AL, 08h ; Load the number 8 into the AL register

ADD AL, 09h ; Add the number 9, AL = 17

Overflow in nibble: AF: = 1

AAA ; Since the auxiliary carry flag (AF = 1) is set, the result is corrected (AL: = 7).

The overflow is now marked by the carry flag (CF = 1).

Note: The machine commands used come from the IA-32