PhysicsTeacher.in

High School Physics + more

DAA Instruction in 8085 for BCD addition

In this post, we will study how to use DAA Instruction in 8085 for BCD addition.

DAA is the 8085 instruction that supports BCD addition. The addition of BCD is done like binary addition, using the ADD instruction. DAA is used to convert the result of the binary sum (Available in the Accumulator) into a BCD number. This instruction cannot be used to directly convert binary numbers into BCD numbers.

This instruction uses Auxiliary Carry and Carry flag to achieve this conversion. During the execution of DAA instruction, the processor checks the lower order 4-bits in the Accumulator. If it is greater than 9 or if the Auxiliary Carry flag is set, then 6 is added to this lower order nibble. Similarly, if the higher order 4-bits is greater than 9 or if the Carry flag is set, then 6 is added to the higher order 4-bits of the Accumulator. The result of this operation in Accumulator will be the BCD equivalent of the sum.

Execution of DAA instruction results

Step 1

If the value of the low order four bits (D3-D0) in the Accumulator is greater than 9 or if auxiliary carry flag (AC) is set, the instruction adds 6 (06) to the low-order four bits.

Step 2

If the value of the high order four bits (D7-D4) in the accumulator is greater than 9 or if carry flag (CY) is set, the instruction adds 6(06) to the high-order four bits.

BCD Addition Rule

The rule for addition of two BCD numbers is given below:

  • Add the two numbers using the rules for binary addition.
  • If a four-bit sum is equal to or less than 9, it is a valid BCD number.
  • If a four-bit sum is greater than 9, or if a carry is generated, it is an invalid result.
  • Add 6 (0110)2 to the four-bit sum in order to skip the six invalid states (A to F) and return the code to BCD. If a carry results when 6 is added, add the carry to the next four-bit group.

Example of BCD addition

Addition of 9 BCD (1001 ) and 4 BCD ( 0100)

Addition of 9 BCD (1001 ) and 4 BCD( 0100)
Addition of 9 BCD (1001 ) and 4 BCD( 0100)

DAA Instruction in 8085 for BCD addition – how to program?

We will solve a sample problem involving BCD addition with the help of DAA instruction.

Problem statement: Add two 2-digit packed BCD numbers (24)BCD and (36)BCD and store the sum (in BCD form) in memory location C200.

Program:

MVI B, 24H ; load the first BCD number in REG.B

MVI A, 36H ; load the 2nd BCD number in REG.A

ADD B ; Add the content of REG. A with the content of REG.B

DAA ; DAA is used to convert the result of the binary sum (5A H) available in the REG.A into a BCD number.

STA C200H ; store the sum in BCD form (here it is 60 BCD) in memory location C200H

HLT ; Terminate program execution.

Explanation

Explanation - Use of DAA instruction for BCD addition in 8085

Sub-routine which will perform the same task as DAA

Assume the DAA instruction is not present. Write a sub routine which will perform the same task as DAA.

Sample Problem:

Sub-routine which will perform the same task as DAA
Sub-routine which will perform the same task as DAA

Note: To check auxiliary carry flag it is necessary to get the flag register contents in one of the registers and then we can check the auxiliary carry flag by checking bit 4 of that register. To get the flag register contents in any general purpose register we require stack operation and therefore stack pointer is initialized at the beginning of the source program.

Author of this post

This post is co-authored by Professor Saraswati Saha, who is an assistant professor at RCCIIT, a renowned degree engineering college in India. Professor Saha teaches subjects related to digital electronics & microprocessors.

See also  Square of a number using a look-up table (assembly language program)
Scroll to top
error: physicsTeacher.in