Related Articles

Related Articles

8085 program to subtract two BCD numbers
  • Last Updated : 18 May, 2018

Problem – Write an assembly language program in 8085 microprocessor to subtract two 8 bit BCD numbers.

Example –

Algorithm –

  1. Load the data from address 2051 in A
  2. Move the data from A to C
  3. Move the data 99 in A
  4. Subtract the contents of registers A and C
  5. Increment the content of A by 1
  6. Move the data from A to B
  7. Load the data from address 2050 in A
  8. Add the contents of A and C and adjust it in BCD format by using DAA instruction
  9. Store the result at memory address 3050
  10. Stop

Program –



MEMORY ADDRESS MNEMONICS COMMENT
2000 LDA 2051 A <- 2051
2003 MOV C, A C <- A
2004 MVI A 99 A <- 99
2006 SUB C A = A – C
2007 INR A A = A + 1
2008 MOV B, A B <- A
2009 LDA 2050 A <- 2050
200C ADD B A = A + B
200D DAA Convert the hexadecimal value to BCD value
200E STA 3050 3050 <- A
2011 HLT Stop

Explanation –

  1. LDA 2051 is used to load the data from address 2051 in A.
  2. MOV C, A is used to move the data from A to C.
  3. MVI A 99 is used to move the data to register A.
  4. SUB C is used to subtract the contents of registers A and C.
  5. INR A is used to increment the content of A by 1.
  6. MOV B, A is used to move the data from A to B.
  7. LDA 2050 is used to load the data from address 2050 in A.
  8. ADD B is used to add the contents of registers A and B.
  9. DAA is used to convert the hexadecimal value in Accumulator to BCD value.
  10. STA 3050 is used to store the contents of A to 3050.
  11. HLT is used end the program.
My Personal Notes arrow_drop_up
Recommended Articles
Page :