Skip to content
Related Articles

Related Articles

Improve Article

8085 program to add 2-BCD numbers

  • Difficulty Level : Basic
  • Last Updated : 23 Aug, 2020

Problem – Write a program to add 2-BCD numbers where starting address is 2000 and the numbers is stored at 2500 and 2501 memory addresses and store sum into 2502 and carry into 2503 memory address.

Example –

Algorithm –

  1. Load 00H in a register (for carry)
  2. Load content from memory into register pair
  3. Move content from L register to accumulator
  4. Add content of H register with accumulator
  5. Add 06H if sum is greater than 9 or Auxiliary Carry is not zero
  6. If carry flag is not equal to 1, go to step 8
  7. Increment carry register by 1
  8. Store content of accumulator into memory
  9. Move content from carry register to accumulator
  10. Store content of accumulator into memory
  11. Stop

Program –

2000MVIC, 00H[C] <- 00H, carry
2002LHLD[2500][H-L] <- [2500]
2005MOVA, L[A] <- [L]
2006ADDH[A] <- [A] + [H]
2007DAAAdd 06 if sum > 9 or AC = 1
2008JNC200CJump if no carry
200BINRC[C] <- [C] + 1
200CSTA[2502][A] -> [2502], sum
200FMOVA, C[A] <- [C]
2010STA[2503][A] -> [2503], carry

Explanation – Registers A, C, H, L are used for general purpose

  1. MVI is used to move data immediately into any of registers (2 Byte)
  2. LHLD is used to load register pair direct using 16-bit address (3 Byte instruction)
  3. MOV is used to transfer the data from memory to accumulator (1 Byte)
  4. ADD is used to add accumulator with any of register (1 Byte instruction)
  5. STA is used to store data from accumulator into memory address (3 Byte instruction)
  6. DAA is used to check if sum > 9 or AC = 1 add 06 (1 Byte instruction)
  7. JNC is used jump if no carry to given memory location (3 Byte instruction)
  8. INR is used to increase given register by 1 (1 Byte instruction)
  9. HLT is used to halt the program

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.


My Personal Notes arrow_drop_up
Recommended Articles
Page :