Sunteți pe pagina 1din 82

Lecture 8 and Lecture 9

Fixed Point Arithmetic


CSC208A-Computer Organisation and Architecture
B. Tech. 2016

Course Leaders
Chaitra S., Naveeta, Gp Capt N Rath VSM

1
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Objectives
• At the end of these lectures, students will be able to
– Describe the process of performing basic mathematical
operations on signed and unsigned numbers

– Explain how these mathematical operations are


implemented using register/circuit diagrams

– Identify the need for fast adders and fast multipliers

– Distinguish between restoring division and non restoring


division

2
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Contents
• Addition and Subtraction of Signed Numbers
– Full Adder
– Ripple Carry Adder
– N-bit Ripple Carry Adder

• Multiplication of Unsigned Numbers


– Array Multipliers
– Sequential Circuit Multipliers

• Multiplication of Signed Numbers


– Booth’s Algorithm

• Division of Unsigned Numbers


– Restoring Division
– Non Restoring Division

3
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Contents
• Addition and Subtraction of Signed Numbers
– Full Adder
– Ripple Carry Adder
– N-bit Ripple Carry Adder

• Multiplication of Unsigned Numbers


– Array Multipliers
– Sequential Circuit Multipliers

• Multiplication of Signed Numbers


– Booth’s Algorithm

• Division of Unsigned Numbers


– Restoring Division
– Non Restoring Division

4
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Addition and Subtraction of Signed Numbers
• Consider the addition of two binary numbers X and Y

5
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Addition and Subtraction of Signed Numbers
• The generic expression to arrive at the sum and carry
for each bit is given by

6
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Addition and Subtraction of Signed Numbers
• For example, the addition of the 4 bit unsigned
numbers, 7 and 6 is shown below

7
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Half Adder

8
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Half Adder

9
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Half Adder (Continues…)

10
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Half Adder (Continues…)

11
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Half Adder (Continues…): CD4011
(QUAD 2 Input Nand Gate)

12
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Full Adder

13
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Full Adder: Truth Table

14
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Full Adder: Another Implementation
• The logic expressions for sum and carry out can be implemented
with a 3 input XOR gate and an AND-OR circuit respectively

• This collective implementation is called a Full Adder

15
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Ripple Carry Adder
• A cascaded connection of n full-adder blocks can be used
to add two n-bit numbers

• Since the carries must propagate, or ripple, through this


cascade, the configuration is called a ripple-carry adder

16
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
n Bit Ripple Carry Adder: k n bit FA
• The carry-in into the LSB position provides a
convenient means of adding 1 to a number

• The carry signals are also useful for interconnecting k


adders to form an adder capable of handling input
numbers that are kn bits long

17
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Addition/Subtraction: Overflow
• Arithmetic overflow occurs when the signs of the two
operands are the same, but the sign of the result is
different
Overflow = xn−1yn−1sn−1 + xn−1yn−1s_n−1

• Overflow also occurs when the carry bits cn and cn-1


are different
Overflow = cn ⊕ cn-1

18
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Addition/Subtraction: 2’s Compliment
• Recall that the difference between calculating X + Y and X – Y lies
in the two’s complement
X – Y = X + (2’s complement(Y))
Where,
2’s complement (Y) = 1’s Complement (Y) + 1

This implies that

X – Y = X + 1’s Complement (Y) + 1

• Implementation-wise, the difference between addition and


subtraction is whether there is a (1’s complement +1) component
or not
19
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Addition/Subtraction: 2’s Compliment
• Recall that the difference between calculating X + Y and X – Y lies
in the two’s complement
X – Y = X + (2’s complement(Y))
Where,
2’s complement (Y) = 1’s Complement (Y) + 1

This implies that

X – Y = X + 1’s Complement (Y) + 1

• Implementation-wise, the difference between addition and


subtraction is whether there is a (1’s complement +1) component
or not
20
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Addition/Subtraction Logic Unit

21
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Addition/Subtraction Logic Unit

22
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Addition/Subtraction Logic Unit

0/1

23
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Addition/Subtraction Logic Unit
• This logic can be implemented in the ALU using an
Add/Sub input control line

• Add/Sub input control line is set to 0 for addition


– Y is applied unchanged to one of the adder inputs and Co is
set to 0

• Add/Sub input control line is set to 1 for subtraction


– 1’s complement of Y is calculated using the XOR gates
– 2’s complement is achieved by setting Co to 1

24
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
n bit Ripple Carry Adder- Timing Issues

25
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
4 bit Ripple Carry Adder- Gate Delays

27
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
4 bit Ripple Carry Adder- Gate Delays

28
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
n bit Ripple Carry Adder- Gate Delays
• Consider a 4 bit Adder
x0 y0 x0 y0 x0 y0 x0 y0

FA FA FA FA c0
c4 c3 c2 c1

s3 s2 s1 s0
• s0 available after 1 gate delays, c1 available after 2 gate delays

• s1 available after 3 gate delays, c2 available after 4 gate delays

• s2 available after 5 gate delays, c3 available after 6 gate delays

• s3 available after 7 gate delays, c4 available after 8 gate delays


29
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
n bit Ripple Carry Adder-Timing Issues
• In general, for an n-bit adder
– sn-1 is available after 2n-1 gate delays
– cn is available after 2n gate delays
– Overflow indicator is available after 2n+2 gate delays

• Two approaches can be taken to reduce delay in


adders
– The first approach is to use the fastest possible electronic
technology
– The second approach is to use a logic gate network called a
carry-look ahead network
30
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
A 4 Bit Carry Look Ahead Adder

31
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
A 4 Bit Carry Look Ahead Adder
• A = An An-1 …. A1 A0
• B = Bn Bn-1 …. B1 B0

• Cn = Gn-1+Gn-2.Pn+Gn-3.Pn-2+ … +C0.P0.P1. … .Pn-1

• Gn = An.Bn

• Pn = An XOR Bn

• C1 = G0+C0.P0
• C2 = G1+ G0.P1+C0.P0.P1 32
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Multiplication of Unsigned Numbers

33
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Multiplication of Unsigned Numbers
• The product of two, unsigned, n-digit numbers can be accommodated in
2n digits

• If the multiplier bit is 1, the multiplicand is entered in the appropriate


shifted position and if the multiplier bit is 0, then 0s are entered

• The product is computed at the End one bit at a time by adding the bit
columns from right to left and propagating carry values between columns

34
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Array Multipliers
• Instead of adding the parallel products at the end, we
could add them at each stage

• Rules to implement multiplication are:


– If the ith bit of the multiplier is 1, shift the multiplicand (left) and
add the shifted multiplicand to the current value of the partial
product

– Hand over the partial product (Sum) to the next stage

– Value of the partial product (Sum) at the start stage is 0

35
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Array Multipliers: Processing of 1 bit of m & q

Multiplicand

Multiplier

36
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Array Multipliers: Processing of 1 bit of m & q

Multiplicand

Multiplier

mj AND qj (= mj MULT qj)

37
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Array Multipliers: Processing of 1 bit of m & q

Multiplicand

Multiplier

mj AND qj (= mj MULT qj)

FA Gets Three Inputs


and gives out Two O/Ps

38
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Array Multipliers: Processing of 1 bit of m & q

Multiplicand

Multiplier

mj AND qj (= mj MULT qj)

FA Gets Three Inputs


and gives out Two O/Ps

39
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Array Multipliers
• Multiplicand is shifted by displacing it through an array
of adders

40
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Array Multipliers
• Multiplicand is shifted by displacing it through an array
of adders

Carry Out

41
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Array Multipliers
• Multiplicand is shifted by displacing it through an array
of adders

Carry Out

42
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Disadvantages of Array Multipliers
• Extremely inefficient

• Have a high gate count for multiplying numbers of


practical size such as 32-bit or 64-bit numbers

• Perform only unsigned integer product

• Gate efficiency can be improved by using a mixture of


combinatorial array and sequential techniques
43
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Sequential Circuit Multiplier
• Recall the rule for generating partial products:
– If the ith bit of the multiplier is 1, add the appropriately shifted
multiplicand to the current partial product

• Multiplicand has been shifted left when added to the


partial product

• However, adding a left-shifted multiplicand to an unshifted


partial product is equivalent to adding an unshifted
multiplicand to a right-shifted partial product
44
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Exercise: Seq Mult (13X11)
M
1 1 0 1
Q
1 0 1 1

45
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Exercise: Seq Mult (13X11)
M
1 1 0 1
C A Q
0 0 0 0 0 1 0 1 1

46
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Exercise: Seq Mult (13X11)
M
1 1 0 1
C A Q
0 0 0 0 0 1 0 1 1

0 1 1 0 1 1 0 1 1 Step 1

MX1

47
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Exercise: Seq Mult (13X11)
M
1 1 0 1
C A Q
0 0 0 0 0 1 0 1 1

0 1 1 0 1 1 0 1 1 Add

48
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Exercise: Seq Mult (13X11)
M
1 1 0 1
C A Q
0 0 0 0 0 1 0 1 1

0 1 1 0 1 1 0 1 1 Add

0 1 1 0 1 1 0 1 1

49
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Exercise: Seq Mult (13X11)
M
1 1 0 1
C A Q
0 0 0 0 0 1 0 1 1

0 1 1 0 1 1 0 1 1 Shift 1 bit right

0 1 1 0 1 1 0 1 1

50
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Exercise: Seq Mult (13X11)
M
1 1 0 1
C A Q
0 0 0 0 0 1 0 1 1

0 1 1 0 1 1 0 1 1 Shift 1 bit right

0 0 1 1 0 1 1 0 1 1

51
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Exercise: Seq Mult (13X11)
M
1 1 0 1
C A Q
0 0 0 0 0 1 0 1 1

0 1 1 0 1 1 0 1 1

0 0 1 1 0 1 1 0 1

52
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Exercise: Seq Mult (13X11)
M
1 1 0 1
C A Q
0 0 0 0 0 1 0 1 1

0 1 1 0 1 1 0 1 1

0 0 1 1 0 1 1 0 1
Step 2
0 1 1 0 1 1 1 0 1

MX1

53
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Exercise: Seq Mult (13X11)
M
1 1 0 1
C A Q
0 0 0 0 0 1 0 1 1

0 1 1 0 1 1 0 1 1

0 0 1 1 0 1 1 0 1

0 1 1 0 1 1 1 0 1 Add

54
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Exercise: Seq Mult (13X11)
M
1 1 0 1
C A Q
0 0 0 0 0 1 0 1 1

0 1 1 0 1 1 0 1 1

0 0 1 1 0 1 1 0 1

0 1 1 0 1 1 1 0 1 Add

1 0 0 1 1 1 1 0 1

55
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Exercise: Seq Mult (13X11)
M
1 1 0 1
C A Q
0 0 0 0 0 1 0 1 1

0 1 1 0 1 1 0 1 1

0 0 1 1 0 1 1 0 1

0 1 1 0 1 1 1 0 1 Add

1 0 0 1 1 1 1 0 1

What Next ?

56
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Exercise: Seq Mult (13X11)
M
1 1 0 1
C A Q
0 0 0 0 0 1 0 1 1

0 1 1 0 1 1 0 1 1

0 0 1 1 0 1 1 0 1

0 1 1 0 1 1 1 0 1 Add

1 0 0 1 1 1 1 0 1

Shift Right

57
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Exercise: Seq Mult (13X11)
M
1 1 0 1
C A Q
0 0 0 0 0 1 0 1 1

0 1 1 0 1 1 0 1 1

0 0 1 1 0 1 1 0 1

0 1 1 0 1 1 1 0 1 Add

1 0 0 1 1 1 1 0 1

What Next ?

58
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Exercise: Seq Mult (13X11)
M
1 1 0 1
C A Q
0 0 0 0 0 1 0 1 1

0 1 1 0 1 1 0 1 1

0 0 1 1 0 1 1 0 1

0 1 1 0 1 1 1 0 1 Add

1 0 0 1 1 1 1 0 1

Add…

59
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Exercise: Seq Mult (13X11)
M
1 1 0 1
C A Q
0 0 0 0 0 1 0 1 1

0 1 1 0 1 1 0 1 1

0 0 1 1 0 1 1 0 1

0 1 1 0 1 1 1 0 1 Add

1 0 0 1 1 1 1 0 1

Add…

60
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Panoramic View: Sequential Cct Multiplier Proc
• 1101 (Dec 13) X 1011 (Dec 11) using Sequential Cct
Multiplier (SCM)

61
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Sequential Circuit Multiplier

62
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Sequential Circuit Multiplier

Depending on q0 = 1 or q0 = 0

63
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Sequential Circuit Multiplier-Steps
• If the LSB q0=1:
– Add the multiplicand to A
– Store carry-out in flip-flop C

• Else if q0 = 0
– Do not add

• Shift the contents of register A and Q to the right, and discard q0

• The Add/Noadd signal causes the multiplexer MUX to select 0


when qi = 0, or to select the multiplicand M when qi = 1, to be
added to PPi to generate PP(i + 1)
64
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Try This…
• Show the steps involved in multiplying the numbers
1001 and 1100 using a sequential step multiplier

65
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Multiplication of Signed Numbers
• Consider the case of a positive multiplier and a negative
multiplicand

• When we add a -ve multiplicand to a partial product, we must


extend the sign-bit value of the multiplicand to the left as far as
the product will extend (2n)

66
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Andrew Donald Booth’s Algorithm: 1950 London
• The Booth algorithm generates a 2n-bit product and treats
both positive and negative (2’s complement) n-bit
operands uniformly

• It (the algo) converts strings of 1's in the multiplier


– to a high-order +1 And a
– low-order –1 @ ends of the string

• When a string runs through the MSB, there is no high-


order +1, and the net effect is interpretation as a negative
of the appropriate value
67
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Booth’s Algorithm
• Let m and r be the multiplicand and multiplier, respectively; and let x
and y represent the number of bits in m and r

Step 1: Determine the values of A and S, and the initial value of P. All of
these numbers should have a length equal to (x + y + 1)

– A : Fill the most significant (leftmost) bits with the value of m. Fill the
remaining (y + 1) bits with zeros

– S: Fill the most significant bits with the value of (−m) in two's complement
notation. Fill the remaining (y + 1) bits with zeros

– P: Fill the most significant x bits with zeros. To the right of this, append the
value of r. Fill the least significant (rightmost) bit with a zero.

68
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Booth’s Algorithm: Action based on 2 LSBs of P (Step 2)
• Step 2: If the two least significant (rightmost) bits of P
are:
– 01, find the value of P + A. Ignore any overflow
– 10, find the value of P + S. Ignore any overflow
– 00 & 01 do nothing. Use P directly in the next step
• Step 3: Right Shift P by 1 Bit
• Step 4: Repeat steps 2 and 3 until they have been
done y times

• Step 5: Drop the LSB from P to get mXr


69
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Example
• Find 3 × (−4), with m = 3 and r = −4, and x = 4 and y = 4:

Solution:
m = 0011, -m = 1101, r = 1100
A = 0011 0000 0
S = 1101 0000 0
P = 0000 1100 0

Perform the loop four times

70
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Example
• P = 0000 1100 0(The last two bits are 00)
– P = 0000 0110 0 (Arithmetic right shift)

• P = 0000 0110 0 (The last two bits are 00)


– P = 0000 0011 0 (Arithmetic right shift)

• P = 0000 0011 0 (The last two bits are 10)


– P = 1101 0011 0 (P = P + S)
– P = 1110 1001 1 (Arithmetic right shift)

• P = 1110 1001 1 (The last two bits are 11)


– P = 1111 0100 1 (Arithmetic right shift)

Dropping the last bit,


Product = 1111 0100
71
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Try This…
• Multiply each of the following pairs of signed 2’s-
complement numbers using the Booth algorithm

• In each case, assume that A is the multiplicand and B is


the multiplier

I. A = 010111 and B = 110110


II. A = 110011 and B = 101100
III. A = 001111 and B = 001111
72
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Division of Unsigned Numbers
• Consider the following example for longhand
integer division

– We try to divide 2 by 13 – Does not work

– We try to divide 27 by 13 – Works with quotient 2 and


remainder 1

– We bring the 4 down and append it to the previous


remainder

– We try to divide 14 by 13 – Works. Append 1 to the


quotient and subtract 13 from 14 to get the final
remainder

73
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Restoring Division
• The divisor is positioned appropriately with respect to the
dividend and performs a subtraction

• If the remainder is zero or positive, a quotient bit of 1 is


determined, the remainder is extended by another bit of
the dividend, the divisor is repositioned, and another
subtraction is performed

• If the remainder is negative, a quotient bit of 0 is


determined, the dividend is restored by adding back the
divisor, and the divisor is repositioned for another
subtraction

74
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Circuit Arrangement for Restoring Division

75
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Circuit Arrangement for Restoring Division
• An n-bit positive divisor is loaded into register M and an n-bit
positive dividend is loaded into register Q at the start of the
operation

• Register A is set to 0

• After the division is complete, the n-bit quotient is in register Q


and the remainder is in register A

• The required subtractions are facilitated by using 2’s-


complement arithmetic

• The extra bit position at the left end of both A and M


accommodates the sign bit during subtractions
76
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Algorithm For Restoring Division
• Do the following steps n times:

– Shift A and Q left one bit position.

– Subtract M from A, and place the answer back in A

– If the sign of A is 1, set q0 to 0 and add M back to A (that is,


restore A)

– If the sign of A is 0 set q0 to 1

77
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Example
• Given that dividend = 1000 and divisor = 11, show how
the answer is obtained using the restoring division
algorithm

78
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Try This…
• Given that dividend = 1101 and divisor = 10, show how
the answer is obtained using the restoring division
algorithm

79
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Non Restoring Division
• Consider the sequence of operations that takes place after the
subtraction operation in the preceding algorithm

• If A is positive, we shift left and subtract M, that is, we perform


2A-M

• If A is negative, we restore it by performing A+M, and then we


shift it left and subtract M

• This is equivalent to performing 2A+M

• The q0 bit is appropriately set to 0 or 1 after the correct


operation has been performed

80
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Algorithm for Non-Restoring Division
Stage 1: Do the following two steps n times:
– If the sign of A is 0, shift A and Q left one bit position and
subtract M from A;

– Otherwise, shift A and Q left and add M to A.

– Now, if the sign of A is 0, set q0 to 1; otherwise, set q0 to 0.

Stage 2: If the sign of A is 1, add M to A

• Stage 2 is needed to leave the proper positive remainder


in A after the n cycles of Stage 1
81
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Example-Non Restoring Division

82
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Summary
• The logic expressions for sum and carry out can be implemented with a 3 input
XOR gate and an AND-OR circuit respectively

• Arithmetic overflow occurs when the signs of the two operands are the same,
but the sign of the result is different

• Gate efficiency can be improved by using a mixture of combinatorial array


techniques and sequential techniques requiring less combinational logic

• Adding a left-shifted multiplicand to an unshifted partial product is equivalent


to adding an unshifted multiplicand to a right-shifted partial product

• The Booth algorithm generates a 2n-bit product and treats both positive and
negative 2’s complement n-bit operands uniformly

83
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences

S-ar putea să vă placă și