You are on page 1of 8

NAME: - Tushar Vithoba Bhadrike

ROLL NO: - 03

UID: - 121CP3292A

COMPUTER BRANCH
SUBJECT: - Digital Logic & Computer Organization and Architecture

Experiment no 4

❖ Aim
To implement non-restoring division algorithm

❖ Objective:
1. To design non- restoring with a controller and a Datapath. This will also help in
the learning of control unit design as a finite state machine
2. To understand the advantages of non-restoring division .

❖ Theory:
To perform Non-Restoring division, it is less complex than the restoring one because
simpler operation are involved i.e. addition and subtraction, also now restoring step is
performed. In the method, rely on the sign bit of the register which initially contain zero
named as A. This algorithm is different from the other algorithm because here, there is no
concept of restoration and this algorithm is less complex than the restoring division
algorithm. Let the dividend Q = 0110 and the divisor M = 0100.
The step involved:
Step-1: First the registers are initialized with corresponding values (Q = Dividend, M =
Divisor, A = 0, n = number of bits in dividend)
Step-2: Check the sign bit of register A
Step-3: If it is 1 shift left content of AQ and perform A = A+M, otherwise shift left AQ
and perform A = A-M (means add 2’s complement of M to A and store it to A)
Step-4: Again the sign bit of register A
Step-5: If sign bit is 1 Q[0] become 0 otherwise Q[0] become 1 (Q[0] means least
significant bit of register Q)
Step-6: Decrements value of N by 1
Step-7: If N is not equal to zero go to Step 2 otherwise go to next step
Step-8: If sign bit of A is 1 then perform A = A+M
Step-9: Register Q contain quotient and A contain remainder
Examples: Perform Non-Restoring Division for Unsigned Integer
Dividend =11
Divisor =3
-M =11101
N M A Q Action

4 00011 00000 1011 Start

00001 011_ Left shift AQ

11110 011_ A=A-M

3 11110 0110 Q[0]=0

11100 110_ Left shift AQ

11111 110_ A=A+M

2 11111 1100 Q[0]=0

11111 100_ Left Shift AQ

00010 100_ A=A+M

1 00010 1001 Q[0]=1

00101 001_ Left Shift AQ

00010 001_ A=A-M

0 00010 0011 Q[0]=1

Quotient = 3 (Q)
Remainder = 2 (A)

Flowchart:
Program:

def add(A, M):


carry = 0
Sum = ''

# Iterating through the number


# A. Here, it is assumed that
# the length of both the numbers
# is same
for i in range (len(A)-1, -1, -1):

# Adding the values at both


# the indices along with the
# carry
temp = int(A[i]) + int(M[i]) + carry

# If the binary number exceeds 1


if (temp>1):
Sum += str(temp % 2)
carry = 1
else:
Sum += str(temp)
carry = 0

# Returning the sum from


# MSB to LSB
return Sum[::-1]

# Function to find the compliment


# of the given binary number
def compliment(m):
M = ''

# Iterating through the number


for i in range (0, len(m)):

# Computing the compliment


M += str((int(m[i]) + 1) % 2)

# Adding 1 to the computed


# value
M = add(M, '0001')
return M

# Function to find the quotient


# and remainder using the
# Non-Restoring Division Algorithm
def nonRestoringDivision(Q, M, A):
# Computing the length of the
# number
count = len(M)

comp_M = compliment(M)

# Variable to determine whether


# addition or subtraction has
# to be computed for the next step
flag = 'successful'

# Printing the initial values


# of the accumulator, dividend
# and divisor
print ('Initial Values: A:', A,
' Q:', Q, ' M:', M)

# The number of steps is equal to the


# length of the binary number
while (count):

# Printing the values at every step


print ("\nstep:", len(M)-count + 1,
end = '')

# Step1: Left Shift, assigning LSB of Q


# to MSB of A.
print (' Left Shift and ', end = '')
A = A[1:] + Q[0]

# Choosing the addition


# or subtraction based on the
# result of the previous step
if (flag == 'successful'):
A = add(A, comp_M)
print ('subtract: ')
else:
A = add(A, M)
print ('Addition: ')

print('A:', A, ' Q:',


Q[1:]+'_', end ='')

if (A[0] == '1'):

# Step is unsuccessful and the


# quotient bit will be '0'
Q = Q[1:] + '0'
print (' -Unsuccessful')

flag = 'unsuccessful'
print ('A:', A, ' Q:', Q,
' -Addition in next Step')

else:

# Step is successful and the quotient


# bit will be '1'
Q = Q[1:] + '1'
print (' Successful')

flag = 'successful'
print ('A:', A, ' Q:', Q,
' -Subtraction in next step')
count -= 1
print ('\nQuotient(Q):', Q,
' Remainder(A):', A)

# Driver code
if __name__ == "__main__":

dividend = '0111'
divisor = '0101'

accumulator = '0' * len(dividend)

nonRestoringDivision(dividend,
divisor,
accumulator)

Output:
Conclusion: Hence we have implemented non-restoring division algorithm.

QUESTIONS :

1.What is non restoring algorithm?


Non-restoring division algorithm is used to divide two unsigned integers. The other form of
this algorithm is Restoring Division. This algorithm is different from the other algorithm
because here, there is no concept of restoration and this algorithm is less complex than the
restoring division algorithm
.

2.What are the advantages of non-restoring over restoring division?

The advantage of using non-restoring arithmetic over the standard restoring division is that a
test subtraction is not required; the sign bit determines whether an addition or subtraction
is used. The disadvantage, though, is that an extra bit must be maintained in the partial
remainder to keep track of the sign

3.What is the difference between restoring and non-restoring division algorithm?

restoring method: you add the divisor back, and put 0 as your next quotient digit.

non-restoring method: you don't do that - you keep negative remainder and a digit 1, and
basically correct things by a supplementary
4.Which is the faster division algorithm?

The SRT algorithm

5.Which algorithm is used for division of integers?

Euclidean division

6.What are the limitations of the non-restoring algorithm?

1. The dividend must be expressed as a 2n-bit 2‟s complement number. Thus, for example, the 4 bit
0111 becomes 00000111, and 1001 becomes 11111001.

2. The divisor and the dividend both must be positive.

3. It will not give the correct answer if the divisor is negative and the dividend is positive and vice
versa.

4. It will not give the correct answer if the both dividend and divisor are negative. Future scope of
non-restoring division algorithm is to divide two signed binary numbers.

❖ References
1. Computer Architecture and Organization - John P. Hayes
2. Computer Organization and Architecture - William Stallings
3. Digital Logic and Computer Design - M. Morris Mano. Pearson Education - Prentice
Hall.
4. Digital Principles Foundation of Circuit Design and Application - Arun Kumar Singh.
New Age Publishers.
5. The Art of Electronics - Paul Horowitz and Winfield Hill (1989). Cambridge
University Press
6. Modern Dictionary of Electronics - Rudolf F. Graf (1999). Newness

The End

You might also like