eem16 lecture 7 ucla
TRANSCRIPT
-
8/14/2019 EEM16 Lecture 7 UCLA
1/29
EEM16/CSM51A:Logic Design of Digital Systems
Lecture #7Arithmetic Circuits
Prof. Danijela Cabric
Fall 2013
-
8/14/2019 EEM16 Lecture 7 UCLA
2/29
2(c) 2005 - 2012 W. J. Dally
Numbers
Digital logic works with binary numbers
Each bit has a value based on its position
-
8/14/2019 EEM16 Lecture 7 UCLA
3/29
3(c) 2005 - 2012 W. J. Dally
From Decimal To Binary
Example: 17 10 Convert number to binary base:
17 2 = 8 remainder 1
8 2 = 4 remainder 0
4 2 = 2 remainder 0
2 2 = 1 remainder 0
1 2 = 0 remainder 1
17 10 = 10001 2
MSB
LSB
-
8/14/2019 EEM16 Lecture 7 UCLA
4/29
4(c) 2005 - 2012 W. J. Dally
From Decimal To Binary To Hexadecimal
Example: 1963 10
1963 10 = 0111 1010 1011 2
7 A B hex
-
8/14/2019 EEM16 Lecture 7 UCLA
5/29
Binary addition
1-bit 0+0 = 0, 1+0 = 1, 1+1 = 10
1
6 110+ 3 011
5 101+7 111
0 _ 10 _
01001
110 _
10019 0
1 _
00
11 _
100
111 _
110012
(c) 2005 - 2012 W. J. Dally
-
8/14/2019 EEM16 Lecture 7 UCLA
6/29
6(c) 2005 - 2012 W. J. Dally
Half Adder
HA
a
b
c
s
b
ac
s
-
8/14/2019 EEM16 Lecture 7 UCLA
7/29
7(c) 2005 - 2012 W. J. Dally
One bit of an adder
Counts the number of 1 bits on its input Outputs the result in binary For a half-adder, 2 inputs, output can be 0, 1, or 2 For a full-adder, 3 inputs, output can be 0, 1, 2, or 3
c[i] b[i] a[i] count c[i+1] s[i]0 0 0 0 0 00 0 1 1 0 10 1 0 1 0 10 1 1 2 1 01 0 0 1 0 11 0 1 2 1 01 1 0 2 1 01 1 1 3 1 1
-
8/14/2019 EEM16 Lecture 7 UCLA
8/29
8(c) 2005 - 2012 W. J. Dally
Full adder from a truth table
cin
Majority
a
b
s
cout
c[i] b[i] a[i] count c[i+1] s[i]0 0 0 0 0 00 0 1 1 0 1
0 1 0 1 0 10 1 1 2 1 01 0 0 1 0 11 0 1 2 1 01 1 0 2 1 01 1 1 3 1 1
-
8/14/2019 EEM16 Lecture 7 UCLA
9/29
9
Majority circuit
(c) 2005 - 2012 W. J. Dally
-
8/14/2019 EEM16 Lecture 7 UCLA
10/29
10(c) 2005 - 2012 W. J. Dally
Multi-bit Adder
FA
a[0]
b[0]
a
bcin
cout
s s[0]
cin
FA
a[1]
b[1]
a
bcin
cout
s s[1]
c [ 1 ]
FA
a[n-1]
b[n-1]
a
bcin
cout
s s[n-1]
cout
-
8/14/2019 EEM16 Lecture 7 UCLA
11/29
11(c) 2005 - 2012 W. J. Dally
Negative Integers
Thus far we have only addressed positive integers. What aboutnegative numbers?
3 ways to represent negative integers in binary: Sign Magnitude Ones complement Twos complement
Example: Consider +23 23
Sign Magnitude 0 10111 1 10111 Ones complement 0 10111 1 01000 Twos complement 0 10111 1 01001
-
8/14/2019 EEM16 Lecture 7 UCLA
12/29
12
Twos Complement System
-
8/14/2019 EEM16 Lecture 7 UCLA
13/29
13
Twos complement for n=4
0000
0111
0011
1011
1111
1110
1101
1100
1010
1001
1000
0110
0101
0100
0010
0001
+0
+1
+2
+3
+4
+5
+6
+7-8
-7
-6
-5
-4
-3
-2
-1
0 10 0 = + 4
1 10 0 = - 4
+
-
-
8/14/2019 EEM16 Lecture 7 UCLA
14/29
14
Mapping in Twos complement system
-
8/14/2019 EEM16 Lecture 7 UCLA
15/29
15
Converse Mapping
-
8/14/2019 EEM16 Lecture 7 UCLA
16/29
16
Example of Converse Mapping
-
8/14/2019 EEM16 Lecture 7 UCLA
17/29
17
Change of Sign in 2s Complement System
-
8/14/2019 EEM16 Lecture 7 UCLA
18/29
18
Simpler way
-
8/14/2019 EEM16 Lecture 7 UCLA
19/29
19
Change of Sign Procedure
-
8/14/2019 EEM16 Lecture 7 UCLA
20/29
20(c) 2005 - 2012 W. J. Dally
2s complement makes subtraction easy Represent negative number, x as 2 n x
All arithmetic is done modulo 2 n so no adjustments are necessaryx + ( y) = x + (2 n y) (mod 2 n)consider 4-bit numbers
4 3 = 4 + (16 3) (mod 16)
= 4 + (15 3 + 1)= 0100 + (1111 0011) + 0001= 0100 + 1100 + 0001= 0001
Why do we all use 2s complement?
-
8/14/2019 EEM16 Lecture 7 UCLA
21/29
21
Overflow Detection in Addition
-
8/14/2019 EEM16 Lecture 7 UCLA
22/29
22
Adder
a
nn
b n
sub
a
bcin
cout
s out
n
ovf
Adder a[n-2:0]
n-1b[n-2:0]n-1
sub
a
bcin
cout
s out[n-2:0]
Adder a
bcin
cout
s
n-1n-1
out[n-1]a[n-1]b[n-1]
(c) 2005 - 2012 W. J. Dally
-
8/14/2019 EEM16 Lecture 7 UCLA
23/29
23(c) 2005 - 2012 W. J. Dally
Compare two numbers with subtraction
diff = a b
if diff is negative (sign bit = 1), a a a=b
Compare
a
b
lt
eqn
n
-
8/14/2019 EEM16 Lecture 7 UCLA
24/29
24(c) 2005 - 2012 W. J. Dally
Multiplication
Shifting left multiplies by 2e.g., 5 = 101, 10 = 1010, 20 = 10100
To multiply by 3, compute 3x = x + 2xExample, 7 x 5
1 1 1
x 1 0 11 1 10 0 0
1 1 1
1 0 0 0 1 1
Multiplication
-
8/14/2019 EEM16 Lecture 7 UCLA
25/29
25
Multipliers
25
-
8/14/2019 EEM16 Lecture 7 UCLA
26/29
26
Multiplication Bit Matrix
26
-
8/14/2019 EEM16 Lecture 7 UCLA
27/29
27
a 3 a 2 a 1
b0
b1
b2
b3
a 0
First generate partial products: p ij = a i b j has weight i+j
(c) 2005 - 2012 W. J. Dally
-
8/14/2019 EEM16 Lecture 7 UCLA
28/29
28
a 3 a 2 a 1
b0
b1
b2
b3
a 0
FA 0
p 2
p 1
p 0
FA
FA
FA
FA
FA
p 3
FA
FA
p 4
FAFA
FA
p 5
p 6
FA
0
0
0
p 7
Then sum partial products to get sum
(c) 2005 - 2012 W. J. Dally
-
8/14/2019 EEM16 Lecture 7 UCLA
29/29
29(c) 2005 - 2012 W. J. Dally
Summary
Binary number representation Add numbers a bit at a time 2s complement x = (2 n x) = (2 n 1) x + 1 = neg(x) + 1 Subtract by 2s complement and add Multiply form partial products p ij and sum