Download presentation
Presentation is loading. Please wait.
Published byElisabeth Curtis Modified over 9 years ago
1
Instructor: Alexander Stoytchev http://www.ece.iastate.edu/~alexs/classes/ CprE 281: Digital Logic
2
Signed Numbers CprE 281: Digital Logic Iowa State University, Ames, IA Copyright © Alexander Stoytchev
3
Administrative Stuff HW 5 is due today
4
Administrative Stuff No homework is due next week.
5
Administrative Stuff Labs Next Week Mini-Project This one is worth 3% of your grade. Make sure to get all the points.
6
Administrative Stuff Midterm Exam #1 When: Monday Feb 24. Where: This classroom What: Chapter 1 and Chapter 2 plus number systems The exam will be open book and open notes (you can bring up to 3 pages of handwritten notes).
7
Topics for the Midterm Exam Binary Numbers Octal Numbers Hexadecimal Numbers Conversion between the different number systems Truth Tables Boolean Algebra Logic Gates Circuit Synthesis with AND, OR, NOT Circuit Synthesis with NAND, NOR Converting an AND/OR/NOT circuit to NAND circuit Converting an AND/OR/NOT circuit to NOR circuit SOP and POS expressions
8
Topics for the Midterm Exam Mapping a Circuit to Verilog code Mapping Verilog code to a circuit Multiplexers Venn Diagrams K-maps for 2, 3, and 4 variables Minimization of Boolean expressions using theorems Minimization of Boolean expressions with K-maps Incompletely specified functions (with don’t cares) Functions with multiple outputs
9
Quick Review
10
[ Figure 3.1a from the textbook ] Adding two bits (there are four possible cases)
11
[ Figure 3.1b from the textbook ] Adding two bits (the truth table)
12
[ Figure 3.1c from the textbook ] Adding two bits (the logic circuit)
13
[ Figure 3.1c-d from the textbook ] The Half-Adder
14
Bit position i Addition of multibit numbers [ Figure 3.2 from the textbook ]
15
Problem Statement and Truth Table [ Figure 3.3a from the textbook ][ Figure 3.2b from the textbook ]
16
Let’s fill-in the two K-maps [ Figure 3.3a-b from the textbook ]
17
Let’s fill-in the two K-maps [ Figure 3.3a-b from the textbook ]
18
The circuit for the two expressions [ Figure 3.3c from the textbook ]
19
This is called the Full-Adder [ Figure 3.3c from the textbook ]
20
XOR Magic (s i can be implemented in two different ways)
21
HA s c s c c i x i y i c i1+ s i c i x i y i c i1+ s i (a) Block diagram (b) Detailed diagram A decomposed implementation of the full-adder circuit [ Figure 3.4 from the textbook ]
22
HA s c s c c i x i y i c i1+ s i The Full-Adder Abstraction
23
FA c i x i y i c i1+ s i The Full-Adder Abstraction
24
FA We can place the arrows anywhere xixi yiyi sisi c i+1 cici
25
FA x n –1 c n c n1” y n1– s n1– FA x 1 c 2 y 1 s 1 c 1 x 0 y 0 s 0 c 0 MSB positionLSB position n-bit ripple-carry adder [ Figure 3.5 from the textbook ]
26
FA x n –1 c n c n1” y n1– s n1– FA x 1 c 2 y 1 s 1 c 1 x 0 y 0 s 0 c 0 MSB positionLSB position n-bit ripple-carry adder abstraction
27
x n –1 c n y n1– s n1– x 1 y 1 s 1 x 0 y 0 s 0 c 0 n-bit ripple-carry adder abstraction
28
The x and y lines are typically grouped together for better visualization, but the underlying logic remains the same x n –1 c n y n1– s n1– x 1 y 1 s 1 y 0 s 0 c 0 x 0
30
Math Review: Subtraction 39 15 - ??
31
Math Review: Subtraction 39 15 - 24
32
Math Review: Subtraction 82 61 - ?? 48 26 - ?? 32 11 - ??
33
Math Review: Subtraction 82 61 - 21 48 26 - 22 32 11 - 21
35
Math Review: Subtraction 82 64 - ?? 48 29 - ?? 32 13 - ??
36
Math Review: Subtraction 82 64 - 18 48 29 - 19 32 13 - 19
38
The problems in which row are easier to calculate? 82 64 - ?? 48 29 - ?? 32 13 - ?? 82 61 - ?? 48 26 - ?? 32 11 - ??
39
The problems in which row are easier to calculate? 82 64 - 18 48 29 - 19 32 13 - 19 82 61 - 21 48 26 - 22 32 11 - 21 Why?
40
Another Way to Do Subtraction 82 – 64 = 82 + 100 – 100 - 64
41
Another Way to Do Subtraction 82 – 64 = 82 + 100 – 100 - 64 = 82 + (100 – 64) - 100
42
Another Way to Do Subtraction 82 – 64 = 82 + 100 – 100 - 64 = 82 + (100 – 64) - 100 = 82 + (99 + 1 – 64) - 100
43
Another Way to Do Subtraction 82 – 64 = 82 + 100 – 100 - 64 = 82 + (100 – 64) - 100 = 82 + (99 + 1 – 64) - 100 = 82 + (99 – 64) +1 - 100
44
Another Way to Do Subtraction 82 – 64 = 82 + 100 – 100 - 64 = 82 + (100 – 64) - 100 = 82 + (99 + 1 – 64) - 100 = 82 + (99 – 64) +1 - 100 Does not require borrows
45
9’s Complement (subtract each digit from 9) 99 64 - 35
46
10’s Complement (subtract each digit from 9 and add 1 to the result) 99 64 - 35 + 1 = 36
47
Another Way to Do Subtraction 82 – 64 = 82 + (99 – 64) +1 - 100
48
Another Way to Do Subtraction 82 – 64 = 82 + (99 – 64) +1 - 100 9’s complement
49
Another Way to Do Subtraction 82 – 64 = 82 + (99 – 64) +1 - 100 = 82 + 35 + 1 - 100 9’s complement
50
Another Way to Do Subtraction 82 – 64 = 82 + (99 – 64) +1 - 100 = 82 + 35 + 1 - 100 9’s complement 10’s complement
51
Another Way to Do Subtraction 82 – 64 = 82 + (99 – 64) +1 - 100 = 82 + 35 + 1 - 100 9’s complement = 82 + 36 - 100 10’s complement // add the first two
52
Another Way to Do Subtraction 82 – 64 = 82 + (99 – 64) +1 - 100 = 82 + 35 + 1 - 100 = 118 - 100 9’s complement = 82 + 36 - 100 = 18 10’s complement // add the first two // delete the leading 1
54
b n1– b 1 b 0 Magnitude MSB (a) Unsigned number b n1– b 1 b 0 Magnitude Sign (b) Signed number b n2– 0 denotes 1 denotes + –MSB Formats for representation of integers [ Figure 3.7 from the textbook ]
55
Sign and magnitude 1’s complement 2’s complement Negative numbers can be represented in following ways
56
Let K be the negative equivalent of an n-bit positive number P. Then, in 1’s complement representation K is obtained by subtracting P from 2 n – 1, namely K = (2 n – 1) – P This means that K can be obtained by inverting all bits of P. 1’s complement
57
Find the 1’s complement of … 0 1 0 0 1 0 0 1 1 1 0 0 1 1
58
Find the 1’s complement of … 0 1 0 0 1 0 0 1 1 1 0 0 1 1 1 0 1 1 0 1 1 0 0 0 1 1 0 0 Just flip 1's to 0's and vice versa.
59
Example of 1’s complement addition + 0 1 1 1 0 1 0 0 1 0 5+ () 2+ () 7+ () +
60
Example of 1’s complement addition [ Figure 3.8 from the textbook ] + 1 1 0 0 1 0 0 0 1 0 2+ () 5– 3- +
61
Example of 1’s complement addition [ Figure 3.8 from the textbook ] + 0 0 1 0 0 1 1 1 0 1 1 1 0 0 1 1 5+ () 3+ () + 2–
62
Example of 1’s complement addition [ Figure 3.8 from the textbook ] + 0 1 1 1 1 0 1 1 0 1 1 1 1 0 0 0 5– 7– + 2–
63
Let K be the negative equivalent of an n-bit positive number P. Then, in 2’s complement representation K is obtained by subtracting P from 2 n, namely K = 2 n – P 2’s complement
64
For a positive n-bit number P, let K 1 and K 2 denote its 1’s and 2’s complements, respectively. K 1 = (2 n – 1) – P K 2 = 2 n – P Since K 2 = K 1 + 1, it is evident that in a logic circuit the 2’s complement can computed by inverting all bits of P and then adding 1 to the resulting 1’s-complement number. Deriving 2’s complement
65
Find the 2’s complement of … 0 1 0 0 1 0 0 1 1 1 0 0 1 1
66
Find the 2’s complement of … 0 1 0 0 1 0 0 1 1 1 0 0 1 1 1 0 1 11 1 1 0 1 0 0 11 1 0 1
67
Quick Way to find 2’s complement Scan the binary number from right to left Copy all bit that are 0 from right to left Stop at the first 1 Copy that 1 as well Invert all remaining bits
68
[ Table 3.2 from the textbook ] Interpretation of four-bit signed integers
69
Example of 2’s complement addition [ Figure 3.9 from the textbook ] + 0 1 1 1 0 1 0 0 1 0 5+ () 2+ () 7+ () +
70
Example of 2’s complement addition [ Figure 3.9 from the textbook ] + 1 1 0 1 1 0 1 1 0 0 1 0 2+ () 5– 3– +
71
Example of 2’s complement addition [ Figure 3.9 from the textbook ] + 0 0 1 1 0 1 1 1 1 0 1 ignore 5+ () 3+ () + 2–
72
Example of 2’s complement addition [ Figure 3.9 from the textbook ] + 1 0 0 1 1 0 1 1 1 1 1 0 1 ignore 5– 7– + 2–
74
Example of 2’s complement subtraction – 0 1 0 0 1 0 5+ () 2+ () 3+ () – 1 ignore + 0 0 1 1 0 1 1 1 1 0 [ Figure 3.10 from the textbook ]
75
Example of 2’s complement subtraction [ Figure 3.10 from the textbook ] – 1 0 1 1 0 0 1 0 – 1 ignore + 1 0 0 1 1 0 1 1 1 1 1 0 5– 7– 2+ ()
76
Example of 2’s complement subtraction [ Figure 3.10 from the textbook ] – 0 1 1 1 1 0 5+ () 7+ () – + 0 1 1 1 0 1 0 0 1 02–
77
Example of 2’s complement subtraction [ Figure 3.10 from the textbook ] – 1 0 1 1 1 1 1 0 – + 1 1 0 1 1 0 1 1 0 0 1 02– 5– 3–
78
[ Figure 3.11 from the textbook ] Graphical interpretation of four-bit 2’s complement numbers
79
Take Home Message Subtraction can be performed by simply adding the 2’s complement of the second number, regardless of the signs of the two numbers. Thus, the same adder circuit can be used to perform both addition and subtraction !!!
80
s 0 s 1 s n1– x 0 x 1 x n1– c n n-bit adder y 0 y 1 y n1– c 0 Add Sub control [ Figure 3.12 from the textbook ] Adder/subtractor unit
81
XOR Tricks y control out
82
y 0 y XOR as a repeater
83
y 1 y XOR as an inverter
84
s 0 s 1 s n1– x 0 x 1 x n1– c n n-bit adder y 0 y 1 y n1– c 0 Add Sub control [ Figure 3.12 from the textbook ] Addition: when control = 0
85
s 0 s 1 s n1– x 0 x 1 x n1– c n n-bit adder y 0 y 1 y n1– c 0 Add Sub control [ Figure 3.12 from the textbook ] Addition: when control = 0 0 0 00
86
s 0 s 1 s n1– x 0 x 1 x n1– c n n-bit adder y 0 y 1 y n1– c 0 Add Sub control [ Figure 3.12 from the textbook ] Addition: when control = 0 0 0 00 y n-1 y1y1 y0y0 …
87
s 0 s 1 s n1– x 0 x 1 x n1– c n n-bit adder y 0 y 1 y n1– c 0 Add Sub control [ Figure 3.12 from the textbook ] Subtraction: when control = 1
88
s 0 s 1 s n1– x 0 x 1 x n1– c n n-bit adder y 0 y 1 y n1– c 0 Add Sub control [ Figure 3.12 from the textbook ] Subtraction: when control = 1 1 1 11
89
s 0 s 1 s n1– x 0 x 1 x n1– c n n-bit adder y 0 y 1 y n1– c 0 Add Sub control [ Figure 3.12 from the textbook ] Subtraction: when control = 1 1 1 11 y n-1 y1y1 y0y0 …
90
s 0 s 1 s n1– x 0 x 1 x n1– c n n-bit adder y 0 y 1 y n1– c 0 Add Sub control [ Figure 3.12 from the textbook ] Subtraction: when control = 1 1 1 11 y n-1 y1y1 y0y0 … 1 carry for the first column!
91
++ 1 0 1 1 1 0 0 1 0 0 1 0 1 0 0 1 0 1 1 1 0 0 1 0 7+ () 2+ () 9+ () + ++ 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 1 1 1 1 1 1 0 7+ () 5+ () + 2– 11 c 4 0= c 3 1= c 4 0= c 3 0= c 4 1= c 3 1= c 4 1= c 3 0= 2+ () 7– 5– + 7– 9– +2– Examples of determination of overflow [ Figure 3.13 from the textbook ]
92
++ 1 0 1 1 1 0 0 1 0 0 1 0 1 0 0 1 0 1 1 1 0 0 1 0 7+ () 2+ () 9+ () + ++ 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 1 1 1 1 1 1 0 7+ () 5+ () + 2– 11 c 4 0= c 3 1= c 4 0= c 3 0= c 4 1= c 3 1= c 4 1= c 3 0= 2+ () 7– 5– + 7– 9– +2– Examples of determination of overflow [ Figure 3.13 from the textbook ] Overflow occurs only in these two cases.
93
++ 1 0 1 1 1 0 0 1 0 0 1 0 1 0 0 1 0 1 1 1 0 0 1 0 7+ () 2+ () 9+ () + ++ 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 1 1 1 1 1 1 0 7+ () 5+ () + 2– 11 c 4 0= c 3 1= c 4 0= c 3 0= c 4 1= c 3 1= c 4 1= c 3 0= 2+ () 7– 5– + 7– 9– +2– Examples of determination of overflow [ Figure 3.13 from the textbook ] Overflow occurs only in these two cases. Overflow = c 3 c 4 + c 3 c 4
94
++ 1 0 1 1 1 0 0 1 0 0 1 0 1 0 0 1 0 1 1 1 0 0 1 0 7+ () 2+ () 9+ () + ++ 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 1 1 1 1 1 1 0 7+ () 5+ () + 2– 11 c 4 0= c 3 1= c 4 0= c 3 0= c 4 1= c 3 1= c 4 1= c 3 0= 2+ () 7– 5– + 7– 9– +2– Examples of determination of overflow [ Figure 3.13 from the textbook ] Overflow occurs only in these two cases. Overflow = c 3 c 4 + c 3 c 4 XOR
95
Calculating overflow for 4-bit numbers with only three significant bits
96
Calculating overflow for n-bit numbers with only n-1 significant bits
97
Another way to look at the overflow issue
98
If both numbers that we are adding have the same sign but the sum does not, then we have an overflow.
99
Questions?
100
THE END
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.