Open In App

8085 program to divide two 16 bit numbers

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

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 ADDRESS MNEMONICS COMMENTS
2000 LXI B, 0000H INITIALISE QUOTIENT AS 0000H
2003 LHLD 2052H LOAD THE DIVISOR IN HL
2006 XCHG EXCHANGE HL AND DE
2007 LHLD 2050 LOAD THE DIVIDEND
200A MOV A, L A<-L
200B SUB E A<-A-E
200C MOV L, A L<-A
200D MOV A, H A<-H
200E SBB D A<-A-D
200F MOV H, A H<-A
2010 JC 2017 JUMP WHEN CARRY
2013 INX B B<-B+1
2014 JMP 200B  
2017 DAD D HL<-DE+HL
2018 SHLD 2056 HL IS STORED IN MEMORY
201B MOV L, C L<-C
201C MOV H, B H<-B
201D SHLD 2054 HL IS STORED IN MEMORY
2020 HLT TERMINATES 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.

     


Previous Article
Next Article

Similar Reads

8085 program to divide two 8 bit numbers
Problem - Write 8085 program to divide two 8 bit numbers. Example - Algorithm - Start the program by loading the HL pair registers with address of memory location. Move the data to B Register. Load the second data into accumulator. Compare the two numbers to check carry. Subtract two numbers. Increment the value of carry. Check whether the repeated
2 min read
8085 program to find maximum of two 8 bit numbers
Problem - Write a assembly language program to find maximum of two 8 bit numbers in 8085 microprocessor. Assumptions - Starting memory locations and output memory locations are 2050, 2051 and 3050 respectively. Example - Algorithm - Load value in the accumulator Then, copy the value to any of the register Load next value in the accumulator Compare
1 min read
8085 program to add two 8 bit numbers
Problem - Write an assembly language program to add two 8 bit numbers stored at address 2050 and address 2051 in 8085 microprocessor. The starting address of the program is taken as 2000. Example - Algorithm - Load the first number from memory location 2050 to accumulator.Move the content of accumulator to register H.Load the second number from mem
2 min read
8085 program to multiply two 8 bit numbers
Problem - Multiply two 8 bit numbers stored at address 2050 and 2051. Result is stored at address 3050 and 3051. Starting address of program is taken as 2000. Example - Algorithm - We are taking adding the number 43 seven(7) times in this example.As the multiplication of two 8 bit numbers can be maximum of 16 bits so we need register pair to store
3 min read
8085 program to add two 16 bit numbers
Problem: Write an assembly language program to add two 16 bit numbers by using: 8-bit operation16-bit operation Example: 1. Addition of 16-bit numbers using 8-bit operation: It is a lengthy method and requires more memory as compared to the 16-bit operation. Algorithm: Load the lower part of the first number in the B register.Load the lower part of
3 min read
8085 program to swap two 8-bit numbers
Problem: Write an assembly language program to swap two 8-bit numbers stored in an 8085 microprocessor. Assumption: Suppose there are two 8-bit numbers. One 8-bit number is stored at location 2500 memory address and another is stored at location 2501 memory address. Let 05 be stored at location 2500 and 06 be stored at location 2501 (not necessaril
4 min read
8085 program to subtract two 8-bit numbers with or without borrow
Problem – Write a program to subtract two 8-bit numbers with or without borrow where first number is at 2500 memory address and second number is at 2501 memory address and store the result into 2502 and borrow into 2503 memory address. Example – Algorithm – Load 00 in a register C (for borrow)Load two 8-bit number from memory into registersMove one
3 min read
8085 program to find larger of two 8 bit numbers
Problem - Write a program in 8085 microprocessor to find out larger of two 8-bit numbers, where numbers are stored in memory address 2050 and 2051, and store the result into memory address 3050. Example - Algorithm - Load two numbers from memory 2050 &amp; 2051 to register L and H .Move one number(H) to Accumulator A and subtract other number(L) fr
3 min read
8085 program to multiply two 8 bit numbers using logical instructions
Prerequisite - Logical instructions in 8085 microprocessor Problem - Write a assembly language program multiply two 8 bit numbers and store the result at memory address 3050 in 8085 microprocessor. Example - The value of accumulator(A) after using RLC instruction is: A = 2n*A Where n = number of times RLC instruction is used. Assumptions - Assume t
2 min read
8085 program to swap two 16 bit numbers using Direct addressing mode
Problem - Write a program to swap two 16-bit numbers using direct addressing mode where starting address is 2000 and the first 16-bit number is stored at 3000 and the second 16-bit number is stored at 3002 memory address. Example – Algorithm – Load a 16-bit number from memory 3000 into a register pair (H-L)Exchange the register pairsLoad a 16-bit n
2 min read