Open In App

8085 program to add three 16 bit numbers stored in registers

Last Updated : 05 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Problem – Write an assembly language program to add three 16 bit numbers stored in register HL, DE, BC and store the result in DE with minimum number of instructions. Example – Assumptions –

  1. Numbers to be added are already stored in register HL, DE, BC
  2. Numbers stored in register are such that final result should not be greater than FFFF

DAD D performs the following task:

  H <- H + D 
  L <- L + E 

DAD instruction take one argument and that argument can be register B, D, H or SP XCHG instruction exchanges the content of register D with H and E with L Algorithm –

  1. Add the content of DE register in HL and store the result in HL by help of DAD instruction
  2. Move the content of register B in D and C in E
  3. Repeat step 1
  4. Use XCHG instruction to swap the content of DE with HL. We will get the result in DE

Program –

MEMORY ADDRESS MNEMONICS COMMENT  
2000 DAD D H <- H + D, L <- L + E  
2001 MOV D, B D <- B  
2002 MOV E, C E <- C  
2003 DAD D H <- H + D, L <- L + E  
2004 XCHG Swap content of HL with DE  
2005 HLT END  

Explanation –

  1. DAD D – adds the content of register D in H and register E in L and store the result in HL
  2. MOV D, B – moves the value of register B in register D
  3. MOV E, C moves the value of register C in register E
  4. Same as step 1
  5. XCHG – exchange the content of register H with register D and L with E.
  6. HLT – stops executing the program and halts any further execution

Advantages of using this program include:

Flexibility: This program can be modified easily to add more than three numbers or to store the result in different registers.

Speed: The 8085 microprocessor is a relatively fast processor, so this program can perform the addition of three 16-bit numbers quickly.

Efficiency: The use of registers for storing the numbers and the result makes the program efficient in terms of memory usage.

Disadvantages of using this program include:

Complexity: Assembly language programming can be complex, and this program may be difficult to understand and modify for beginners.

Limited capacity: The 8085 microprocessor has a limited address space and can only access a maximum of 64KB of memory, which may be a limitation when working with larger datasets.

Error-prone: Assembly language programming is prone to errors, and a mistake in the code can cause unexpected results or even crash the program or the entire system.


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

Similar Reads