BCD Arithmetic

DAA instruction usage.

Darshan N
Updated: 19 March 2026
6 min read

In 8085 microprocessor programming, arithmetic operations on decimal numbers require special handling because the processor internally works in binary. BCD (Binary Coded Decimal) arithmetic allows decimal results to be maintained in a form directly readable by humans, which is essential in calculators, digital clocks, and instrumentation systems.

BCD Arithmetic in 8085Binary Add (ADD/ADI)Result may exceed BCDDAA InstructionAdjust accumulatorValid BCD Result0–9 in each nibbleExample: 35 + 47 (BCD)Binary: 35H + 47H = 7CHAfter DAA: 82H (correct BCD)DAA Correction RulesLower nibble > 9 or AC=1: add 06HUpper nibble > 9 or CY=1: add 60HDAA works ONLY after ADD, ADC, SUB (packed BCD)Affects: CY, AC, Z, S, P flags
Figure 1: BCD Arithmetic flow in 8085 using DAA instruction

Core Concept: Why BCD Arithmetic Needs Special Treatment

The 8085 processor performs all arithmetic in pure binary. When two BCD digits are added in binary, the result can easily fall outside the valid BCD range (0 to 9 per nibble). For example, adding BCD 7 and BCD 8 gives 0FH in binary, but in BCD it should give 15 (one carry, digit 5). The processor cannot automatically handle this discrepancy.

The DAA (Decimal Adjust Accumulator) instruction corrects the accumulator contents after a binary addition so that the result represents a valid packed BCD number. Packed BCD means one byte holds two decimal digits, upper nibble being the tens digit and lower nibble being the units digit.

DAA checks two conditions. First, if the lower nibble of the accumulator is greater than 9 or if the Auxiliary Carry (AC) flag is set, it adds 06H to the accumulator. Second, if the upper nibble exceeds 9 or the Carry (CY) flag is set, it adds 60H. These two corrections together ensure both nibbles stay within the valid BCD range 0 through 9.

Mathematical Expression and Correction Logic

For packed BCD addition of two bytes A and B, the binary sum S = A + B may produce an invalid nibble. The correction factor applied by DAA is determined as follows:

If (lower nibble of S) > 9 or AC = 1, correction = 06H is added to S. If after this addition (upper nibble of result) > 9 or CY = 1, correction = 60H is further added. The final result is the correct BCD sum. This can be expressed as: Corrected Result = S + (06H if lower nibble invalid) + (60H if upper nibble invalid)

The DAA instruction only applies correctly after ADD, ADC, or SUB operations involving the accumulator. It cannot be used independently to convert arbitrary binary values to BCD.

Practical Understanding: Subtraction and Multi-Byte BCD

BCD subtraction in 8085 is handled using the 10s complement method because the DAA instruction technically works correctly for BCD subtraction as well, provided the subtraction was performed using SUB or SBB. After subtraction, DAA adjusts the accumulator if the result went negative in BCD terms, setting the carry flag to indicate borrow.

For multi-byte BCD operations, such as adding two 4-digit BCD numbers stored in two bytes each, the carry produced after each DAA step must be propagated to the next higher byte pair using ADC. This mirrors the standard multi-precision arithmetic technique but applied to BCD pairs.

Real applications include digital clocks where seconds, minutes, and hours are stored in BCD, score counters in embedded systems, and billing displays. Maintaining BCD format avoids the overhead of converting binary to decimal for output.

Example
Given:
Two packed BCD numbers: 48H (represents decimal 48) and 35H (represents decimal 35)

Why this formula applies:
Binary addition of BCD numbers may produce invalid nibbles; DAA corrects both nibbles.

Formula:
Step 1: Binary ADD accumulator with operand
Step 2: Apply DAA to correct result

Substitution:
  MVI A, 48H     ; Load 48 (BCD) into accumulator
  MVI B, 35H     ; Load 35 (BCD) into B
  ADD B          ; Binary: 48H + 35H = 7DH
                 ; Lower nibble D (13) > 9, AC may be set
  DAA            ; Lower nibble correction: 7DH + 06H = 83H
                 ; Upper nibble 8 is valid, no upper correction

Calculation:
  48H + 35H = 7DH (binary)
  7DH + 06H = 83H (after DAA lower nibble fix)
  Upper nibble 8 is within range, no 60H addition needed

Final Answer with units:
  Accumulator = 83H, which represents BCD 83 (decimal 83 = 48 + 35). Correct.
Exam Tip: DAA must always follow ADD or ADC for BCD addition. A common GATE trap is applying DAA after direct register loads or logical instructions, which gives undefined or wrong results. Also note: DAA works on packed BCD (two digits per byte), not unpacked BCD (one digit per byte).

DAA Correction: Step-by-Step Mechanism

  • After binary ADD, check lower nibble: if it is A through F (10 to 15) or AC flag is 1, add 06H to the accumulator.
  • After the above step, check upper nibble: if it is A through F or CY flag is 1, add 60H to the accumulator.
  • If 60H is added in upper nibble correction, the Carry flag is set, indicating a BCD carry out of the most significant digit pair.
  • DAA affects S, Z, AC, P, and CY flags based on the adjusted result.
  • For BCD subtraction (using SUB/SBB), DAA still adjusts correctly, and CY set after DAA indicates a borrow from the BCD result.

Quick Revision

  • BCD arithmetic in 8085 requires a two-step process: binary ADD followed by DAA instruction.
  • DAA corrects lower nibble by adding 06H if nibble > 9 or AC = 1.
  • DAA corrects upper nibble by adding 60H if nibble > 9 or CY = 1.
  • DAA is valid only after ADD, ADC, SUB, or SBB instructions.
  • Packed BCD stores two decimal digits per byte; valid range per nibble is 0 to 9.
  • For multi-byte BCD, carry from DAA must be propagated using ADC to the next byte pair.
  • Common trap: Using DAA after MOV or logical operations yields incorrect results.

BCD Arithmetic Quiz

Test your knowledge of the DAA instruction and BCD correction in 8085 arithmetic operations.

Question 1 of 3

Q1.After executing "ADD B" where A = 39H and B = 28H, the accumulator holds 61H. When DAA is executed immediately after, what does DAA do to this result?