# 8085 program to divide two 16 bit numbers

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. Intialise 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.
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 –

center>

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
200B MOV A, L A<-L
200C SUB E A<-A-E
200D MOV L, A L<-A
200E MOV A, H A<-H
200F SBB D A<-A-D
2010 MOV H, A H<-A
2011 JC 2018 JUMP WHEN CARRY
2014 INX B B<-B+1
2015 JMP 200B
2019 SHLD 2056 HL IS STORED IN MEMORY
201C MOV L, C L<-C
201D MOV H, B H<-B
201E SHLD 2054 HL IS STORED IN MEMORY
2021 HLT TERMINATES THE PROGRAM

Explanation –

1. LXI B, 0000H: intialise BC register as 0000H.
3. XCHG: exchange the content of HL pair with DE pair register.
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.
12. INX B: increment BC register by one.
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.