@opcode(<EOL><NUM_LIT>, <EOL>)<EOL><INDENT>def instruction_DAA(self, opcode):<DEDENT>
a = self.accu_a.value<EOL>correction_factor = <NUM_LIT:0><EOL>a_hi = a & <NUM_LIT> <EOL>a_lo = a & <NUM_LIT> <EOL>if a_lo > <NUM_LIT> or self.H: <EOL><INDENT>correction_factor |= <NUM_LIT><EOL><DEDENT>if a_hi > <NUM_LIT> and a_lo > <NUM_LIT>:<EOL><INDENT>correction_factor |= <NUM_LIT><EOL><DEDENT>if a_hi > <NUM_LIT> or self.C: <EOL><INDENT>correction_factor |= <NUM_LIT><EOL><DEDENT>new_value = correction_factor + a<EOL>self.accu_a.set(new_value)<EOL>self.clear_NZ() <EOL>self.update_NZC_8(new_value)<EOL>
The sequence of a single-byte add instruction on accumulator A (either
ADDA or ADCA) and a following decimal addition adjust instruction
results in a BCD addition with an appropriate carry bit. Both values to
be added must be in proper BCD form (each nibble such that: 0 <= nibble
<= 9). Multiple-precision addition must add the carry generated by this
decimal addition adjust into the next higher digit during the add
operation (ADCA) immediately prior to the next decimal addition adjust.

source code forms: DAA

CC bits "HNZVC": -aa0a

Operation:
    ACCA' ← ACCA + CF(MSN):CF(LSN)

where CF is a Correction Factor, as follows:
the CF for each nibble (BCD) digit is determined separately,
and is either 6 or 0.

Least Significant Nibble
CF(LSN) = 6 IFF 1)    C = 1
             or 2)    LSN > 9

Most Significant Nibble
CF(MSN) = 6 IFF 1)    C = 1
             or 2)    MSN > 9
             or 3)    MSN > 8 and LSN > 9

Condition Codes:
H    -    Not affected.
N    -    Set if the result is negative; cleared otherwise.
Z    -    Set if the result is zero; cleared otherwise.
V    -    Undefined.
C    -    Set if a carry is generated or if the carry bit was set before the operation; cleared otherwise.