Open In App

DAA instruction in 8085

The DAA instruction is a powerful tool in assembly language programming particularly while working with the BCD numbers in microprocessors like the Intel 8085. The use of DAA is largely dependent on the architecture of the microprocessor. It allows for the correct interpretation of the result of adding two BCD numbers. The DAA (Decimal Adjust Accumulator ) instruction is a specific command used in some microprocessors, such as Intel 8085. The purpose of the DAA instruction is to adjust the contents of the Accumulator to represent a valid BCD (Binary-Coded Decimal) number after performing an addition operation. The DAA instruction allows the addition of numbers represented in 8-bit packed BCD code. It is used immediately after normal addition instruction operating on BCD codes. This instruction assumes the Accumulator register as the source and the destination, and hence it requires no operand.

What is DAA Instruction?

The DAA (Decimal Adjust Accumulator ) instruction in the 8085 microprocessor is used for the addition of BCD (binary-coded Decimal). The addition of BCD is done similarly to the binary addition using the ADD instruction. DAA is used to convert the result of the BCD sum which is available in the accumulator into a binary number. This instruction cannot be used directly to convert binary numbers into BCD numbers.



The DAA instruction is used after instructions like ADD, ADI, ACI, ADC, etc. After the execution of these instructions, the result is in hexadecimal form (in Accumulator). The DAA instruction operates on this result and gives the final result in decimal form.

Working Principle and Syntax

The working principle of DAA instruction is as follows :

Syntax and Usage

Rules of DAA instruction

Note : Lower order bits is also referred as Least significant bits and higher order bits is referred as Most significant bits.

Timing Diagram of DAA Instruction

The DAA instruction requires 1 Byte and 1 machine cycle and 4 T-States. So this DAA instruction is used to support the Binary Coded Decimal addition . This requires 1-Byte , 1-Machine Cycle(opcode fetch) and 4 T-States for execution as shown in the timing diagram.

Timing diagram of DAA

Solved Examples

Let us consider we want to add two Hexa-decimal numbers 38H and 45H. The representation of these numbers in BCD are 0011 1000 and 0100 0101. The addition of these BCD numbers will be 0111 1101 which would be 7D in Hexadecimal and 125 in decimal but the actual addition of 38H and 45H is 83H . So, the error occurs in the addition of two BCD numbers . To correct this error in the addition DAA instruction is used which adjusts the Carry and Auxiliary carry flags . In such cases we can use DAA to have the BCD sum as outcome. All we need to do is to add the BCD numbers and store it in Accumulator and then execute the DAA instruction.

Here is the detail explanation of this example :

MVI A, 38H ; 
MVI B, 45H ;
ADD B ;
DAA ;

In the above example , Accumulator A is loaded with 38H and register B is loaded with 45H

A <—— 38H == 0011 1000 (BCD form)

B <—— 45H == 0100 0101 (BCD form)

(+)

————

0111 1101 == 7D

Here lower order 4-bits (1101) is greater than 9 so 06H is added to adjust (DAA addition)

7D H == 0111 1101

06H == 0000 0110

(+)

————

1000 0011 == 83H

Consider 38H and 41H , The representation of these numbers in BCD are 0011 1000 and 0100 0001 . The addition of these two BCD numbers gives 0111 1001 . In the resultant BCD sum both the lower order bits and higher order bits are less than 9 So even though if we execute DAA instruction it doesn’t change the result. If we convert this resultant BCD number into Hexadecimal form we get 79H and at the same time if we add the 38H and 41H we get 79H which is same.

MVI A, 38H ; 
MVI B, 41H ;
ADD B ;
DAA ;

Here A is loaded with 38H and B is loaded with 41H.

A <—— 38H == 0011 1000 (BCD form)

B <—— 41H == 0100 0001 (BCD form)

(+)

————

0111 1001 == 79H

Since lower order bits 1001 is less than 9 and higher order bits 0111 is also less than 9 no need to perform DAA instruction .

Consider 24H and 36H , The representation of these numbers in BCD are 0010 0100 and 0011 0110 . The addition of these two BCD numbers gives 0101 1010 . In the resultant BCD sum the lower order bits are higher than 9 and the higher order bits are less than 9 So we need to add 06h to the lower order bits. If we convert this resultant BCD number into Hexadecimal form we get 5AH and at the same time if we add the 24H and 36H we get 60H both are not same so we need to execute DAA to adjust carry in BCD number.

MVI A, 24H ; 
MVI B, 36H ;
ADD B ;
DAA ;

Here A is loaded with 24H and B is loaded with 36H.

A <—— 24H == 0010 0100 (BCD form)

B <—— 36H == 0011 0110 (BCD form)

(+)

————

0101 1010 == 5AH

Since lower order bits is greater than 9 we need to add 06H to lower bits.

5AH == 0101 1010

06H == 0000 0110

(+)

————

0110 0000 == 60H

Advantages and Disadvantages of DAA

Given below is some of the Advantages and Disavantages of DAA

Advantages of DAA

Disadvantages of DAA

Conclusion

The DAA instruction is a powerful tool in the assembly language programming particularly while working with the BCD numbers in microprocessors like the intel 8085. It allows for the correct interpretation of the result of adding two BCD numbers. However it is important to remember its limitations and ensure it’s used correctly in programs.

DAA is not a universal solution for all BCD operations. It is specifically designed for adjusting the result of an addition operation. For other operations such as subtraction,multiplication, or division , additional logic or other instructions may be needed.

Futhermore,the use of DAA is largely dependent on the architecture of the microprocessor. While it’s commonly used in intel 8085 and similar microprocessors, not all the microprocessors or programming languages support the DAA instruction. Therefore, it is applicability may be limited in some contexts.

In conclusion, while the DAA instruction has its limitations and is not universally applicable, it remains a valuable tool for assembly language programmers working with BCD arithmetic on compatible microprocessors. It’s simplicity and efficiency can greatly simplify the process of performing BCD addition,making it s useful instruction to understand and utilize.

FAQs on DAA instruction

What is Timing Diagram ?

Timing Diagram is a graphical representation.It depicts the graphical representation of the execution time for each instruction. The execution time is represented in T-states. Instruction Cycle: The time required to execute an instruction .

What are Arithmetic Instructions in 8085 ?

Arithmetic instructions in the 8085 microprocessor are commands that allow the processor to perform arithmetic operations such as addition, subtraction, multiplication, and division. These instructions manipulate data in the accumulator and other registers to perform mathematical computations.

What is Machine Cycle ?

It is the time required for completing a single operation. This operation can be accessing memory for read/write operation or accessing I/O device. There can be 3 to 6 clock periods or T-states in a machine cycle.


Article Tags :