Skip to main content

8085 ALP: divide two bytes

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.

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.

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.

        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.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Microprocessor chapter 2 questions →