Let us suppose that we store the two 8 bit numbers that are
to be divided in the memory location 9000H and 9001H. Now the remainder of these
numbers is to be stored in 9002H and the quotient is to be stored in 9003H.
Algorithm:
- Start
- Initialize register C with 00.
- Load into accumulator directly from location 9000H.
- Move content of A into register B.
- Load into accumulator directly from 9001H.
- Compare register B with accumulator A.
- If no carry is present go to 8 else go to 11.
- Subtract contents of register B from accumulator A.
- Increment the value of register c.
- Go to 6.
- Store data present in accumulator into memory location 9002H.
- Move contents of register C into accumulator A.
- Store data present in accumulator A into memory location 9003H.
- Terminate the program.
Program Code:
MVI C, 00H
LDA 9000H
MOV B, A
LDA 9001H
UP:
CMP B
JC LAST
SUB B
INR C
JMP UP
LAST:
STA 9002H
MOV A, C
STA 9003H
HLT
Register C is initialized
with 00 to store the quotient value. The first 8 bit number is loaded into the
accumulator A and is then moved into register B which is the divisor
(meaning that the 8 bit number stored in 9000H is the divisor). And the second
8 bit number is then loaded into the accumulator which is the dividend.
The content of the accumulator is compared with the contents of B register. If
the content of accumulator A is less than content of register B then the carry
flag is set. If the carry flag is not set, then the content of accumulator A is
subtracted with the content of register B and after subtraction, the quotient
(i.e. register C) is incremented by one. Again, the content of the accumulator
is compared with the contents of B register and these steps are repeated as long
as the content of accumulator A is less than the content of register B. If the
carry flag is set, then the instructions:
SUB B
INR C
are skipped and
the content of accumulator which is the remainder is stored into memory
location 9002H and the content of register C is now moved into accumulator A
and is stored into memory location 9003H which is the quotient.
Output:
Here, the data in address 9000 i.e. 04 is the divisor. And
the data in address 9001H i.e. 12 is the dividend. The data of location 9002H
is the remainder and the data in 9003 is the quotient.
Example 2 |
Here, 15 is the divisor and 03 is the dividend and 03 is the
remainder since division cannot take place so 00 is the quotient.
well explained
ReplyDeleteVery well explained
ReplyDeleteI understood clearly...
ReplyDeleteThat means we have entere the value of dividend first ....
ReplyDeleteAnd also we have to tell the user