8085 program to divide two 8 bit numbers

Problem – Write 8085 program to divide two 8 bit numbers.

Example –

Algorithm –

  1. Start the program by loading the HL pair registers with address of memory location.
  2. Move the data to B Register.
  3. Load the second data into accumulator.
  4. Compare the two numbers to check carry.
  5. Subtract two numbers.
  6. Increment the value of carry.
  7. Check whether the repeated subtraction is over.
  8. Then store the results(quotient and remainder) in given memory location.
  9. Terminate the program.

Program –

2000 LXI H, 2050
2003 MOV B, M B<-M
2004 MVI C, 00 C<-00H
2006 INX H
2007 MOV A, M A<-M
2008 CMP B
2009 JC 2011 check for carry
200C SUB B A<-A-B
200D INR C C<-C+1
200E JMP 2008
2011 STA 3050 3050<-A
2014 MOV A, C A<-C
2015 STA 3051 3051<-A
2018 HLT terminate the program

Explanation – Registers A, H, L, C, B are used for general purpose.

  1. LXI H, 2050 will load the HL pair register with the address 2050 of memory location.
  2. MOV B, M copies the content of memory into register B.
  3. MVI C, 00 assign 00 to C.
  4. INX H increment register pair HL.
  5. MOV A, M copies the content of memory into accumulator.
  6. CMP B compares the content of accumulator and register B.
  7. JC 2011 jump to address 2011 if carry flag is set.
  8. SUB B subtract the content of accumulator with register B and store the result in accumulator.
  9. INR C increment the register C.
  10. JMP 2008 control will shift to memory address 2008.
  11. STA 3050 stores the remainder at memory location 3050.
  12. MOV A, C copies the content of register into accumulator.
  13. STA 3051 stores the remainder at memory location 3051.
  14. HLT stops executing the program and halts any further execution.

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.