Open In App

DAA instruction in 8085

Last Updated : 26 Apr, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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 :

  • Add the two BCD numbers: This is done like binary addition using the ADD instruction. The result of this addition is stored in the Accumulator.
  • Execute the DAA instruction: This adjusts the contents of the accumulator to contain the correct BCD result.
  • The working of DAA instruction depends on the contents of the Accumulator , Carry Flag(Cy) and the Auxiliary Carry (AC) flag. In effect, it adds 00H , 06H , 60H , or 66H to the Accumulator to get the correct BCD sum in the Accumulator.

Syntax and Usage

  • The DAA instruction is used after instructions like ADD, ADI, ACI, ADC, etc. That adds two BCD numbers.After the execution of these instructions, the result is in BCD form in the Accumulator .
  • The DAA instruction is executed to adjust the result to a valid BCD number.

Rules of DAA instruction

  • This instruction uses auxiliary carry and carry flags. During the execution of DAA instruction the processor checks the lower order 4-bits and higher order 4-bits in the accumulator.
  • If the lower-order 4-bits in the accumulator is <=9 and the auxiliary flag is 0 then the value will not be altered.
  • if the lower-order 4 bits in the accumulator is greater than 9 , or if the auxiliary carry flag is set then 6 is added to its lower order nibble.
  • In the similar way if the higher order 4-bits is less than 9 or the carry flag is 0 then the value will not be altered.
  • 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 accumulator . The result of this operation in Accumulator will be the BCD equivalent of the sum.

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-8085-DAA

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

  • DAA supports Binary Coded Decimal(BCD) addition . It allows the addition of BCD numbers using binary addition,and then converts the binary sum into a BCD number.
  • DAA helps in efficient use of memory by reducing the need for additional instructions to perform BCD addition and this instruction can be used in multiple programs that require BCD addition promoting code reusability.

Disadvantages of DAA

  • The main Disadvantage of DAA instruction is this cannot be used for Binary Coded Decimal Subtraction. To accomplish decimal subtraction with the Intel 8085 instruction set, a sequence of instructions must be executed since direct decimal subtraction is not available.
  • This instruction cannot be used directly to convert binary numbers into BCD numbers instead this converts the result of a binary sum into BCD number.

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.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads