Sem 6‎ > ‎MPRC LAB‎ > ‎

P6: Division of two 8 bit numbers.

posted Apr 7, 2013, 2:11 AM by Neil Mathew   [ updated Apr 7, 2013, 2:12 AM by Neil Mathew ]

Division. 
Clarify the terms Divisor, Dividend, Quotient and Remainder:


Like I explained in multiplication, division is nothing but repeated subtraction. However, the programming is handled differently. In multiplication, the loop continued n number of times (for multiplication m x n). This was done by decrementing the register holding the value n and a condition when it would become zero. (JNZ). 

In division however, we need to count the number of possible subtractions/deductions that can take place and therefore we increment a register to record the quotient. And this should be in an unconditional loop(JMP), broken only when the divisor is smaller than the divident. We'll use the accumulator as the dividend which will later hold the remainder once the loop is over.

We need 3 registers in this case.

A for storing the divident, which later holds the remainder.
B for storing the divisor
C for storing the quotient

PROGRAM:

MVI C, 00
LXI H, 2500
MOV A, M
INX H
MOV B, M
LOOP CMP B
JC OVER
SUB B
INR C
JMP LOOP
OVER STA 2601 (remainder)
MOV A,C
STA 2600 (quotient)
RST1








Comments