8085 program to divide two 16 bit numbers - GeeksforGeeks

26 Jul, 2021
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 –  
Initialise register BC as 0000H for Quotient.  Load the divisor in HL pair and save it in DE register pair.  Load the dividend in HL pair.  Subtract the content of accumulator with E register.  Move the content A to C and H to A.  Subtract with borrow the content of A with D.  Move the value of accumulator to H.  If CY=1, goto step 10, otherwise next step.  Increment register B and jump to step 4.  ADD both contents of DE and HL.  Store the remainder in memory.  Move the content of C to L & B to H.  Store the quotient in memory.  
Initialise register BC as 0000H for Quotient.  
Load the divisor in HL pair and save it in DE register pair.  
Load the dividend in HL pair.  
Subtract the content of accumulator with E register.  
Move the content A to C and H to A.  
Subtract with borrow the content of A with D.  
Move the value of accumulator to H.  
If CY=1, goto step 10, otherwise next step.  
Increment register B and jump to step 4.  
ADD both contents of DE and HL.  
Store the remainder in memory.  
Move the content of C to L & B to H.  
Store the quotient in memory.  
Program –  
Explanation –  
LXI B, 0000H: initialise BC register as 0000H.  LHLD 2052H: load the HL pair with address 2052.  XCHG: exchange the content of HL pair with DE pair register.  LHLD 2050: load the HL pair with address 2050.  MOV A, L: move the content of register L into register A.  SUB E: subtract the contents of register E with contents of accumulator.  MOV L, A: move the content of register A into register L.  MOV A, H: move the content of register H into register A.  SBB D: subtract the contents of register D with contents of accumulator with carry.  MOV H, A: move the content of register A into register H.  JC 2017: jump to address 2017 if there is carry.  INX B: increment BC register by one.  JMP 200B: jump to address 200B.  DAD D: add the contents of DE and HL pair.  SHLD 2056: stores the content of HL pair into memory address 2056 and 2057.  MOV L, C: move the content of register C into register L.  MOV H, B: move the content of register B into register H.  SHLD 2054: stores the content of HL pair into memory address 2054 and 2055.  HLT: terminates the execution of program.  
LXI B, 0000H: initialise BC register as 0000H.  
LHLD 2052H: load the HL pair with address 2052.  
XCHG: exchange the content of HL pair with DE pair register.  
LHLD 2050: load the HL pair with address 2050.  
MOV A, L: move the content of register L into register A.  
SUB E: subtract the contents of register E with contents of accumulator.  
MOV L, A: move the content of register A into register L.  
MOV A, H: move the content of register H into register A.  
SBB D: subtract the contents of register D with contents of accumulator with carry.  
MOV H, A: move the content of register A into register H.  
JC 2017: jump to address 2017 if there is carry.  
INX B: increment BC register by one.  
JMP 200B: jump to address 200B.  
DAD D: add the contents of DE and HL pair.  
SHLD 2056: stores the content of HL pair into memory address 2056 and 2057.  
MOV L, C: move the content of register C into register L.  
MOV H, B: move the content of register B into register H.  
SHLD 2054: stores the content of HL pair into memory address 2054 and 2055.  
HLT: terminates the execution of program.  
 
ShaktirajDaudra
unmesh_mandal
gabaa406
microprocessor
system-programming
Computer Organization & Architecture
microprocessor
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Architecture of 8085 microprocessor
Computer Organization and Architecture | Pipelining | Set 2 (Dependencies and Data Hazard)
Direct Access Media (DMA) Controller in Computer Architecture
Pin diagram of 8086 microprocessor
Difference between SRAM and DRAM
Computer Organization | Different Instruction Cycles
Shift Micro-Operations in Computer Architecture
I2C Communication Protocol
Difference between RISC and CISC processor | Set 2
General purpose registers in 8086 microprocessor