Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

8085 program to divide two 16 bit numbers

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Problem – Write an assembly language program in 8085 microprocessor to divide two 16 bit numbers. 

Assumption – 
 

  • Starting address of program: 2000 
     
  • Input memory location: 2050, 2051, 2052, 2053 
     
  • Output memory location: 2054, 2055, 2056, 2057. 
     

Example – 
 

INPUT:
       (2050H) = 04H
       (2051H) = 00H 
       (2052H) = 02H 
       (2053H) = 00H
OUTPUT:
        (2054H) = 02H
        (2055H) = 00H
        (2056H) = FEH
        (2057H) = FFH 

RESULT: 
Hence we have divided two 16 bit numbers. 

Algorithm – 
 

  1. Initialise register BC as 0000H for Quotient. 
     
  2. Load the divisor in HL pair and save it in DE register pair. 
     
  3. Load the dividend in HL pair. 
     
  4. Subtract the content of accumulator with E register. 
     
  5. Move the content A to C and H to A. 
     
  6. Subtract with borrow the content of A with D. 
     
  7. Move the value of accumulator to H. 
     
  8. If CY=1, goto step 10, otherwise next step. 
     
  9. Increment register B and jump to step 4. 
     
  10. ADD both contents of DE and HL. 
     
  11. Store the remainder in memory. 
     
  12. Move the content of C to L & B to H. 
     
  13. Store the quotient in memory. 
     

Program – 
 

MEMORY ADDRESSMNEMONICSCOMMENTS
2000LXI B, 0000HINITIALISE QUOTIENT AS 0000H
2003LHLD 2052HLOAD THE DIVISOR IN HL
2006XCHGEXCHANGE HL AND DE
2007LHLD 2050LOAD THE DIVIDEND
200AMOV A, LA<-L
200BSUB EA<-A-E
200CMOV L, AL<-A
200DMOV A, HA<-H
200ESBB DA<-A-D
200FMOV H, AH<-A
2010JC 2017JUMP WHEN CARRY
2013INX BB<-B+1
2014JMP 200B 
2017DAD DHL<-DE+HL
2018SHLD 2056HL IS STORED IN MEMORY
201BMOV L, CL<-C
201CMOV H, BH<-B
201DSHLD 2054HL IS STORED IN MEMORY
2020HLTTERMINATES THE PROGRAM

Explanation – 
 

  1. LXI B, 0000H: initialise BC register as 0000H. 
     
  2. LHLD 2052H: load the HL pair with address 2052. 
     
  3. XCHG: exchange the content of HL pair with DE pair register. 
     
  4. LHLD 2050: load the HL pair with address 2050. 
     
  5. MOV A, L: move the content of register L into register A. 
     
  6. SUB E: subtract the contents of register E with contents of accumulator. 
     
  7. MOV L, A: move the content of register A into register L. 
     
  8. MOV A, H: move the content of register H into register A. 
     
  9. SBB D: subtract the contents of register D with contents of accumulator with carry. 
     
  10. MOV H, A: move the content of register A into register H. 
     
  11. JC 2017: jump to address 2017 if there is carry. 
     
  12. INX B: increment BC register by one. 
     
  13. JMP 200B: jump to address 200B. 
     
  14. DAD D: add the contents of DE and HL pair. 
     
  15. SHLD 2056: stores the content of HL pair into memory address 2056 and 2057. 
     
  16. MOV L, C: move the content of register C into register L. 
     
  17. MOV H, B: move the content of register B into register H. 
     
  18. SHLD 2054: stores the content of HL pair into memory address 2054 and 2055. 
     
  19. HLT: terminates the execution of program. 
     

Advantages:

  • The program is a simple and efficient way to divide two 16-bit numbers using the 8085 microprocessor.
     
  • The program uses only a few instructions and requires minimal memory space, making it easy to implement in a microcontroller.
     
  • The program produces accurate results since it performs a series of repetitive subtractions to calculate the quotient and remainder.
     
  • The program can be easily modified to divide larger or smaller numbers by changing the memory addresses.
     

Disadvantages:

  • The program is computationally intensive and time-consuming since it requires a series of repetitive subtractions to calculate the quotient and remainder.
     
  • The program is not very efficient in terms of memory usage since it requires several registers to store the operands and intermediate results.
     
  • The program is not very scalable since it requires a large number of iterations to divide large numbers, which may cause overflow or underflow conditions.
     
  • The program does not handle divide by zero or other error conditions, which may occur if the divisor is zero or the dividend is smaller than the divisor.
     
  • The program does not provide any error checking or reporting mechanism, which may make it difficult to identify errors or faults in the program.

     

My Personal Notes arrow_drop_up
Last Updated : 10 Apr, 2023
Like Article
Save Article
Similar Reads