Monday, March 23, 2015

Two's complement division algorithm or Signed division algorithm

                    

                       Flowchart of Two's complement division

Signed division algorithm,two's complement division algorithm
fig:- Flowchart of Two's complement division


Algorithm


1. M <- Divisor
    Q <- Dividend



2. Shift A,Q left 1 bit position

3. If M and A has same sign perform
                A <- A-M,
                Otherwise A <- A+M

4. The step 3 is successful if the sign of A is same before and after the operation.
            a. If Successful or A=0, then set Q=1
            b. If unsuccessful and A not equal to 0, set Q <- 0 and restore previous value of A.

5. Repeat step 2 through 4 for 'n' times.


Example of Two's Complement division

 1.  (7/3)
 


A
Q
M
Comments
0000
0111
0011
Initial value
0000
1110
0011
Shift left A,Q by 1 bit
1101
1110
0011
A <- A-M
0000
1110
0011
Q0=0
Restore previous value of A
0001
1100
0011
Shift left A,Q by 1 bit
1110
1100
0011
A <- A-M
0001
1100
0011
Q0=0
Restore previous value of A
0011
1000
0011
Shift left A,Q by 1 bit
0000
1000
0011
A <- A-M
0000
1001
0011
Set Q0=1
Restore current value of A
0001
0010
0011
Shift left A,Q by 1 bit
1110
0010
0011
A <- A- M
0001
0010

Q0=0
Restore previous value of A


Ans (Q.A)=(0010.0001)

Note if first value is negative like(-7/3) or both values are negative like(-7/-3) then initial value of A=1111.
 




1 comment: