---
title: "8085 ALP: divide two bytes"
subject: "Microprocessor"
chapter: 2
key: "semester_4/microprocessor:alp-8085-divide-bytes"
source: https://www.bctengineer.com/q/semester_4/microprocessor/alp-8085-divide-bytes
site: BCT Engineering
---

# 8085 ALP: divide two bytes

Microprocessor · Chapter 2: Programming with 8085 Microprocessor

- Asked in: 2070 Magh, 8 marks
- Video: [Division of two 8 bit numbers in 8085|Division program in 8085 microprocessor|8085 microprocessor](https://www.youtube.com/watch?v=AyXLB67-FN4) — Scratch Learners
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/microprocessor/alp-8085-divide-bytes
- Whole chapter: https://www.bctengineer.com/md/semester_4/microprocessor/chapter-2

## Question

Write an assembly language program in 8085 to divide a byte stored in memory location 9070 H by byte stored in 9071 H and store the remainder and quotient at 9072 H and 9073 H respectively.

## Short answer

Divide by repeated subtraction of the divisor from the dividend; each successful subtraction increments the quotient. The remaining dividend is the remainder. If divisor is zero, store FFH in both result locations. For 100÷7, quotient = 0EH, remainder = 02H.

## Answer

**Method:** repeated subtraction. The divisor is subtracted from the dividend as long as the dividend is not smaller than the divisor; each successful subtraction increments the quotient. What is left is the remainder. A divide-by-zero check is included to prevent an endless loop.


```asm
        LXI H,9070H
        MOV A,M         ; A = dividend (9070H)
        INX H
        MOV B,M         ; B = divisor (9071H)
        INR B
        DCR B           ; test divisor for zero
        JZ ERROR
        MVI C,00H       ; C = quotient
LOOP:   CMP B           ; CY = 1 if A < B
        JC DONE
        SUB B           ; subtract divisor
        INR C           ; count it
        JMP LOOP
DONE:   INX H           ; HL = 9072H
        MOV M,A         ; remainder
        INX H
        MOV M,C         ; quotient at 9073H
        HLT
ERROR:  INX H           ; divide by zero: store FFH in both
        MVI M,0FFH
        INX H
        MVI M,0FFH
        HLT
```


**Example:** 9070H = 64H (100), 9071H = 07H gives quotient 0EH (14) at 9073H and remainder 02H at 9072H.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. How does the program find the quotient and the remainder?
   A. It shifts the dividend right once for each bit in the divisor
   B. It uses the 8085 DIV instruction to get both results
   C. It subtracts the divisor while the dividend is not less than it; the count is the quotient, the leftover the remainder
   D. It adds the divisor to itself until the sum equals the dividend
   Answer: C. The 8085 has no divide instruction. Each successful SUB B increments C (the quotient), and the value left in A when it falls below B is the remainder. (Key point: Division by repeated subtraction: count = quotient, leftover = remainder)

2. In the loop, what do CMP B and JC DONE do?
   A. CMP B sets CY = 1 if A < B, so JC DONE stops when no more subtraction is possible
   B. CMP B subtracts B from A, and JC loops while there is a carry
   C. CMP B sets Z = 1 if A < B, and JC jumps on zero
   D. CMP B sets CY = 1 if A > B, so the loop stops when the dividend is larger
   Answer: A. CMP B works out A - B without changing A. A borrow (CY = 1) means A < B, so the remaining A is the remainder and the program jumps to DONE. (Key point: CMP B sets CY = 1 when A < B, which ends the loop)

3. Why does the program run INR B followed by DCR B?
   A. To round the divisor up by one before dividing
   B. To clear the carry flag before the first CMP B
   C. To start the quotient at one instead of zero
   D. To set Z if B is 0 (B is unchanged), so a zero divisor goes to ERROR
   Answer: D. MOV does not affect flags, so INR B then DCR B returns B to its original value while setting Z if B is 0. With a zero divisor, CMP B would never set CY and the loop would never end. (Key point: INR B / DCR B tests for a zero divisor, which would otherwise loop forever)

4. If 9070H = 64H (100) and 9071H = 07H, what does the program store?
   A. 9072H = 0EH and 9073H = 02H
   B. 9072H = 02H (remainder) and 9073H = 0EH (quotient)
   C. 9072H = 14H and 9073H = 02H
   D. 9072H = 02H and 9073H = 07H
   Answer: B. 100 / 7 gives a quotient of 14 (0EH) and a remainder of 2. The question asks for the remainder at 9072H and the quotient at 9073H, and that is the order the program stores them. (Key point: The remainder goes to 9072H and the quotient to 9073H)

## Related in Microprocessor

- [8085 ALP: interchange two bits of bytes](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-interchange-bits) — Microprocessor, chapter 2
- [8085 ALP: exchange bits D6 and D2](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-exchange-d6-d2) — Microprocessor, chapter 2
- [8085 ALP: square of ten numbers](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-square-numbers) — Microprocessor, chapter 2
- [8085 ALP: compare two tables of 16-bit data](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-compare-tables-1ffffh) — Microprocessor, chapter 2
- [8085 ALP: add two tables, sum and carry](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-add-two-tables) — Microprocessor, chapter 2
- [8085 ALP: transfer data with more than 3 ones](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-ones-greater-than-3) — Microprocessor, chapter 2

## Related in other subjects

- [Interfacing: 512-byte RAM with 8085](https://www.bctengineer.com/question.md?key=semester_5%2Finstrumentation_ii%3Arag-ram-512-interface) — Instrumentation II, chapter 2
- [C program: sum of two 8-bit BCD numbers](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3A8051-bcd-sum-c) — Embedded System, chapter 9
- [Short note: Stored program control](https://www.bctengineer.com/question.md?key=semester_8%2Ftelecommunications%3Ashort-note-spc-digital-exchange) — Telecommunications, chapter 4
- [PCM switching and stored program control](https://www.bctengineer.com/question.md?key=semester_8%2Ftelecommunications%3Apcm-switching-spc) — Telecommunications, chapter 4
