Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Division

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 19

CST-204

Division

A division algorithm provides a quotient and a remainder when


we divide two number.

dividend
Quotient q=
divisor

Dividend = q ˣ divisor + remainder

April 4, 2019
Division: Introduction
• Division Algorithm can be grouped into two classes:
following algorithms.
Long Division method
Subtractive Algorithms: Restoring Division, Non-
Restoring Division, SRT Division (Sweeney, Robertson,
and Tocher)
Multiplicative Algorithm: Newton Raphson, Goldschmidt
division
Division by Constant
Approximation Algorithms
Subtractive algorithms
• Restoring and Non-Restoring Binary Division
Slow: Execution time is proportional to the divisor length
Digit recurrence algorithms: retire a fixed number of quotient
bits in every iteration.
 Low complexity, utilize small area, and have relatively large
latencies
Issues: radix, the choice of allowed quotient digits, and the
representation of the intermediate remainder.
Larger radices can reduce the latency, but increase the time
for each iteration.
Restoring Division Algorithm
• Restoring: value of register A is restored after
each iteration.
• register Q contain quotient and register A
contain remainder.
• N-bit dividend is loaded in Q and divisor is
loaded in M.
Restoring Division Algorithm
• Step-1: First the registers are initialized with corresponding values (Q =
Dividend, M = Divisor, A = 0, n = number of bits in dividend)
• Step-2: Then the content of register A and Q is shifted right as if they
are a single unit
• Step-3: Then content of register M is subtracted from A and result is
stored in A
• Step-4: Then the most significant bit of the A is checked if it is 0 the
least significant bit of Q is set to 1 otherwise if it is 1 the least
significant bit of Q is set to 0 and value of register A is restored i.e the
value of A before the subtraction with M
• Step-5: The value of counter n is decremented
• Step-6: If the value of n becomes zero we get of the loop otherwise we
repeat fro step 2
• Step-7: Finally, the register Q contain the quotient and A contain
remainder
Flowchart of Restoring Division Algorithm

Examples:
Dividend = 11 -> 1011
Divisor = 3 -> 0011

Quotient in register Q and


remainder is in register A
Quotient = 3 (Q)
Remainder = 2 (A)
Restoring Division Example 11/3
N M A Q OPERATION

4 00011 00000 1011 initialize

00011 00001 011_ shift left AQ

00011 11110 011_ A=A-M

00011 00001 0110 Q[0]=0 And restore A

3 00011 00010 110_ shift left AQ

00011 11111 110_ A=A-M

00011 00010 1100 Q[0]=0

2 00011 00101 100_ shift left AQ

00011 00010 100_ A=A-M

00011 00010 1001 Q[0]=1

1 00011 00101 001_ shift left AQ

00011 00010 001_ A=A-M

00011 00010 0011 Q[0]=1


Non-Restoring Division Algorithm
• 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.
Non-Restoring Division Algorithm
• 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
Flowchart of Non-Restoring Division Algorithm

Examples:
Dividend = 11 -> 1011
Divisor = 3 -> 0011

Quotient in register Q and


remainder is in register A
Quotient = 3 (Q)
Remainder = 2 (A)
Non-Restoring Division Example 11/3
N M A Q OPERATION

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


Home Assignment
Exercise 1:Divide following unsigned integer using restoring and non-
restoring algorithms:
A) 9/4
B) 10/3
C) 8/2
Exercise 2:Multiply the following signed numbers using Booth
multiplication algorithm
A) -9*4
B) -10*-3
C) -8*2
Exercise 3:Represent -0.75 in floating point format.
Exercise 4:Represent 4.9 in floating point format.
Floating Point Arithmetic
Algorithm for conversion

Let X be a decimal fraction: 0.d1d2..dn


i = 1
Repeat until X = 0 or i = required no.
of binary fractional digits {
Y = X * 2
X = fractional part of Y
Bi = integer part of Y
i = i + 1
}
Conversion from decimal number system to
binary system
Exercise 1: Convert (0.625)10 to its binary form: (0.625)10 = (0.101)2
• 0.625 x 2 = 1.25  extract 1
– 0.25 x 2 = 0.5  extract 0
– 0.5 x 2 = 1.0  extract 1
– 0.0  stop

Exercise 2: Convert (0.6)10 to its binary form: (0.6)10 = (0.1001 1001 1001
…)
– 0.6 x 2 = 1.2  extract 1
– 0.2 x 2 = 0.4  extract 0
– 0.4 x 2 = 0.8  extract 0
– 0.8 x 2 = 1.6  extract 1
Floating Point Number Representation
• IEEE Standard 754 is the representation of floating point used on
most computers.
1. Single precision (float) is 32 bits or 4 bytes with the following
configuration.
1 sign bit 8 exponent 23 fraction
• The sign field for mantissa is 0 for positive or 1 for negative
• In the mantissa, the decimal point is assumed to follow the first ‘1’.
Since the first digit is always a ‘1’, a hidden bit is used to
representing the bit. The fraction is the 23 bits following the first
‘1’. The fraction really represents a 24 bit mantissa.
• The exponent field has a bias of 127, meaning that 127 is added to
the exponent before it’s stored. 20 becomes 127, 21 becomes 128,
2-3 becomes 124, 2-1 becomes 126, etc. When the exponent
becomes -127 (all zeroes), the hidden bit is not used to allow
gradual underflow.
2. Double precision (double) is 64 bites or 8 bytes with the
following configuration.
• The definition of the fields matches single precision.

1 sign bit 11 exponent 52 fraction


• The double precision bias is 1023.
• What value can you not represent because of the hidden bit?
• Certain bit patterns are reserved to represent special values.
Of particular importance is the representation for zero (all bits
zero). There are also patterns to represent infinity, positive
and negative numeric overflow, positive and negative numeric
underflow, and not-a-number (abbreviated NaN).
Example 1. Represent the decimal value 2.5 in 32-bit
floating point format.
2.5 = 10.1b
In normalized form, this is: 1.01 * 21

The mantissa: M = 01000000000000000000000


(23 bits without the leading 1)

The exponent: E = 1 + 127 = 128 = 10000000b


The sign: S = 0 (the value stored is positive)

So, 2.5 = 01000000001000000000000000000000


Example 2: Represent the number -0.00010011b in
floating point form.
0.00010011b = 1.0011 * 2-4

Mantissa: M = 00110000000000000000000 (23 bits


with the integral 1 not represented)

Exponent: E = -4 + 127 = 01111011b

S = 1 (as the number is negative)

Result: 1 01111011 00110000000000000000000


References
1. “Computer Arithmetic: A Quantitative Approach” by John L.
Hennessey & David P. Patterson, Second Edition.
2. “Computer Architecture and Organization” by John P. Hayes,
Third Edition.

You might also like