# /opcodes/daa

Arithmetic // DAA (Decimal Adjust Accumulator)

## Description

This instruction conditionally adjusts the Accumulator for BCD addition and subtraction operations. For addition (ADD, ADC, INC) or subtraction (SUB, SBC, DEC, NEG), the following table indicates the operation being performed: Hex Value Hex Value In Upper In Lower Number C Before Digit H Before Digit Added To C After Operation DAA (Bits 7–4) DAA (Bits 3–0) Byte DAA 09–000–900 0 0 0–8 0 A–F 06 0 00–910–306 0 ADD 0 A–F 0 0–9 60 1 ADC 0 9–F 0 A–F 66 1 INC 0 A–F 1 0–3 66 1 10–200–960 1 1 0–2 0 A–F 66 1 10–310–366 1 SUB 0 0–9 0 0–9 00 0 SBC 0 0–8 1 6–F FA 0 DEC 1 7–F 0 0–9 A0 1 NEG 1 6–7 1 6–F 9A 1

## Example

An addition operation is performed between 15 (BCD) and 27 (BCD); simple decimal arithmetic provides the following result: 15 + 27 42 The binary representations are added in the Accumulator according to standard binary arithmetic, as follows: 0001 0101 + 0010 0111 0011 1100 = 3C The sum is ambiguous. The DAA instruction adjusts this result so that the correct BCD representation is obtained, as follows: 0011 1100 + 0000 0110 0100 0010 = 42