DIVISION OF TWO 8-BIT NUMBERS

ALGORITHM:
1. Quotient and Remainder is set to zero.
2. Dividend is checked with Divisor in each loop.
3. If Dividend is greater than Divisor, subtract Divisor from Dividend.
4. Dividend=Dividend-Divisor.
5. Then, Quotient will be incremented by 1.
6. Repeat from 2 to 5 until Dividend < Divisor.
7. Last remained Dividend is the Remainder.

PROGRAM:
LXI H,0000H
MOV B,M                    ;DIVISOR
MVI C,00                     ;FOR Quotient
INX H
MOV A,M                    ;DIVIDEND
NEXT: CMP B             ;IF A<B, CARRY
JC LOOP
SUB B
INR C                           ;QUOTIENT
JMP NEXT
LOOP: STA 0005H      ;REMAINDER
MOV A,C
STA 0006H                  ;QUOTIENT
HLT

No comments:

Post a Comment