Adapted from Dr. Bassam Kahhaleh’ Slides by Prof. Iyad Jafar
Digital Logic
0907231
0
Chapter 1
Binary Arithmetic
Chapter 5
Arithmetic Logic Circuits
1
Outline
2
Binary Addition
3
Binary Addition
5
5
5
5
+
0
1
1
= Ten ≥ Base
🡺 Subtract a Base and add carry to next digit
1
1
Carry
4
Binary Addition
X
+ Y
C S
0
+ 0
0 0
0
+ 1
0 1
1
+ 0
0 1
1
+ 1
1 0
X: Augend
Y: Addend
S: Sum
C: Carry
5
Binary Addition
1
0
1
1
1
1
1
1
1
1
0
+
0
0
0
0
1
1
1
≥ (2)10
1
1
1
1
1
1
= 61
= 23
= 84
🡺 Subtract a Base and add carry to next digit
6
Unsigned Binary Subtraction
7
Unsigned Binary Subtraction
X
- Y
B D
0
- 0
0 0
0
- 1
? ?
1
- 0
0 1
1
- 1
0 0
0
- 1
1 1
1
2
1 0 0
- 1 1
- 0 0 1
X: Subtrahend Y : Minuend D: Difference B: Borrow
Wrong!
8
Unsigned Binary Subtraction
0 1 1 0
0 1 0 1
-
2
0
0
0 0 0 1
0 0 0 1
0 1 0 1
-
0 0
1
2
1 0 0 0 0
1 1 0 0
-
- 0 1 0 0
1 1
9
Unsigned Binary Subtraction
0
0
1
1
1
0
1
1
1
1
0
−
0
1
0
1
1
1
0
= (10)2
2
2
2
2
1
0
0
0
1
= 77
= 23
= 54
10
Binary Complements
11
Complements
Example (10110000)2
⇨ (01001111)2
If you add a number and its 1’s complement …
1 0 1 1 0 0 0 0
+ 0 1 0 0 1 1 1 1
1 1 1 1 1 1 1 1
12
Complements
|
|
|
|
|
|
13
Complements
Example:
Number:
1’s Comp.:
0 1 0 1 0 0 0 0
1 0 1 1 0 0 0 0
0 1 0 0 1 1 1 1
+ 1
OR
1 0 1 1 0 0 0 0
0
0
0
0
1
0
1
0
14
Complements
|
|
|
|
|
|
15
Unsigned Numbers
16
Unsigned Numbers
17
Signed Numbers
18
Signed Numbers
19
Signed Magnitude Representation
S
Magnitude (Binary)
Positive (+13)
Negative (-13)
0
1101
1
1101
20
Signed Magnitude Representation
|
|
|
|
|
|
21
Signed Magnitude Representation
Signed Magnitude | Value in Decimal | |||
0 | 0 | 0 | | |
0 | 0 | 1 | | |
0 | 1 | 0 | | |
0 | 1 | 1 | | |
1 | 0 | 0 | | |
1 | 0 | 1 | | |
1 | 1 | 0 | | |
1 | 1 | 1 | | |
22
Signed Magnitude Range
24 = 16 Combinations
− 7 ≤ Number ≤ + 7
−23+1 ≤ Number ≤ +23 − 1
−2n−1+1 ≤ Number ≤ +2n−1 − 1
Sign Mag. | Decimal |
0 0 0 0 | + 0 |
0 0 0 1 | + 1 |
0 0 1 0 | + 2 |
0 0 1 1 | + 3 |
0 1 0 0 | + 4 |
0 1 0 1 | + 5 |
0 1 1 0 | + 6 |
0 1 1 1 | + 7 |
1 0 0 0 | − 0 |
1 0 0 1 | − 1 |
1 0 1 0 | − 2 |
1 0 1 1 | − 3 |
1 1 0 0 | − 4 |
1 1 0 1 | − 5 |
1 1 1 0 | − 6 |
1 1 1 1 | − 7 |
23
Signed Magnitude Representation
(+0)10 ⇨ (0 000)2
(−0)10 ⇨ (1 000)2
0 0 1 1 ⇨ (+3)10
+ 1 0 1 1 ⇨ (−3)10
1 1 1 0 ⇨ (−6)10
24
1’s Complement Representation
0
Magnitude (Binary)
1
Code (1’s Comp.)
Sign
Positive
Negative
25
1’s Complement Representation
|
|
|
|
|
|
26
1’s Comp. Representation
Signed 1s Comp. | Value in Decimal | |||
0 | 0 | 0 | | |
0 | 0 | 1 | | |
0 | 1 | 0 | | |
0 | 1 | 1 | | |
1 | 0 | 0 | | |
1 | 0 | 1 | | |
1 | 1 | 0 | | |
1 | 1 | 1 | | |
27
1’s Complement Range
24 = 16 Combinations
− 7 ≤ Number ≤ + 7
−23+1 ≤ Number ≤ +23 − 1
−2n−1+1 ≤ Number ≤ +2n−1 − 1
1s Comp. | Decimal |
0 0 0 0 | + 0 |
0 0 0 1 | + 1 |
0 0 1 0 | + 2 |
0 0 1 1 | + 3 |
0 1 0 0 | + 4 |
0 1 0 1 | + 5 |
0 1 1 0 | + 6 |
0 1 1 1 | + 7 |
1 0 0 0 | − 7 |
1 0 0 1 | − 6 |
1 0 1 0 | − 5 |
1 0 1 1 | − 4 |
1 1 0 0 | − 3 |
1 1 0 1 | − 2 |
1 1 1 0 | − 1 |
1 1 1 1 | − 0 |
28
1’s Comp. Representation
(+0)10 ⇨ (0 000)2
(−0)10 ⇨ (1 111)2
0 0 1 1 ⇨ (+3)10
+ 1 1 0 1 ⇨ (−2)10
0 0 0 0 ⇨ (+0)10
1
1
0 0 0 1 ⇨ (+1)10
X
29
2’s Complement Representation
0
Magnitude (Binary)
1
Code (2’s Comp.)
Sign
Positive
Negative
30
2’s Complement Representation
|
|
|
|
|
|
31
2’s Complement Representation
Signed 2s Comp. | Value in Decimal | |||
0 | 0 | 0 | | |
0 | 0 | 1 | | |
0 | 1 | 0 | | |
0 | 1 | 1 | | |
1 | 0 | 0 | | |
1 | 0 | 1 | | |
1 | 1 | 0 | | |
1 | 1 | 1 | | |
32
2’s Complement Range
24 = 16 Combinations
− 8 ≤ Number ≤ + 7
−23 ≤ Number ≤ + 23 − 1
−2n−1 ≤ Number ≤ + 2n−1 − 1
2s Comp. | Decimal |
0 0 0 0 | + 0 |
0 0 0 1 | + 1 |
0 0 1 0 | + 2 |
0 0 1 1 | + 3 |
0 1 0 0 | + 4 |
0 1 0 1 | + 5 |
0 1 1 0 | + 6 |
0 1 1 1 | + 7 |
1 0 0 0 | − 8 |
1 0 0 1 | − 7 |
1 0 1 0 | − 6 |
1 0 1 1 | − 5 |
1 1 0 0 | − 4 |
1 1 0 1 | − 3 |
1 1 1 0 | − 2 |
1 1 1 1 | − 1 |
33
2’s Complement Representation
(+0)10 ⇨ (0 000)2
(−0)10 ⇨ (0 000)2 ⇨ (1 111) 2 +1 ⇨ 1 (0 000) 2
0 0 1 1 ⇨ (+3)10
+ 1 1 1 0 ⇨ (−2)10
0 0 0 1 ⇨ (+1)10
1
34
Number Representations Summary
| Unsigned Binary | Signed Magnitude | 1’s Comp. | 2’s Comp. |
Range | 0 ≤ N ≤ 15 | -7 ≤ N ≤ +7 | -7 ≤ N ≤ +7 | -8 ≤ N ≤ +7 |
Positive | Binary | Binary | Binary | Binary |
Negative | X | Binary | 1’s Comp. | 2’s Comp. |
0
0
0
1
1
1
35
Example
|
|
|
|
|
|
|
|
36
Example
Decimal | Signed. Mag. | Signed 1’s Comp. | Signed 2’s Comp. |
+12 | | | |
-12 | | | |
+7 | | | |
-7 | | | |
+19 | | | |
-19 | | | |
+16 | | | |
-16 | | | |
37
Example
Decimal | Signed. Mag. | Signed 1’s Comp. | Signed 2’s Comp. |
+12 | 0 1100 | 0 1100 | 0 1100 |
-12 | 1 1100 | 1 0011 | 1 0100 |
+7 | 0 0111 | 0 0111 | 0 0111 |
-7 | 1 0111 | 1 1000 | 1 1001 |
+19 | Out of range | Out of range | Out of range |
-19 | Out of range | Out of range | Out of range |
+16 | Out of range | Out of range | Out of range |
-16 | Out of range | Out of range | 1 0000 |
38
Binary Subtraction Using 1’s Comp. Addition
0 1 0 1
+ 1 1 1 0
(5)10 – (1)10
(+5)10 + (-1)10
0 0 1 1
+
0 1 0 0
0 1 0 1
+ 1 0 0 1
(5)10 – (6)10
(+5)10 + (-6)10
0 1 1 1 0
1 1 1 0
+ 4
− 1
1
39
Binary Subtraction Using 2’s Comp. Addition
in the 2’s Complement.
0 1 0 1
+ 1 1 1 1
(5)10 – (1)10
(+5)10 + (-1)10
1 0 1 0 0
0 1 0 1
+ 1 0 1 0
(5)10 – (6)10
(+5)10 + (-6)10
0 1 1 1 1
+ 4
− 1
40
Binary Adders
41
Binary Adders
X0
X1
X2
X3
Y0
Y1
Y2
Y3
+
S0
S1
S2
S3
C1
C2
C3
C4
42
Binary Adders
43
Binary Adder
HA
x
y
S
C
x y | C S |
0 0 | 0 0 |
0 1 | 0 1 |
1 0 | 0 1 |
1 1 | 1 0 |
x
+ y
───
C S
x
y
S
C
44
Example 5
HA
X0
X1
Y0
Y1
+
S0
S1
C1
C2
X0
Y0
S0
C1
HA
X1
HA
Y1
S1
C2
2-bit
Adder
S0
S1
C2
X0
Y0
X1
Y1
X1+C1
Y1+X1+C1
45
Exercise
46
Exercise
A: A3A2A1A0 and B: B3B2B1B0
2-bit
Adder
S0
S1
Cout
X0
Y0
X1
Y1
2-bit
Adder
S0
S1
Cout
X0
Y0
X1
Y1
47
Binary Adder
x y Cin | Cout S |
0 0 0 | 0 0 |
0 0 1 | 0 1 |
0 1 0 | 0 1 |
0 1 1 | 1 0 |
1 0 0 | 0 1 |
1 0 1 | 1 0 |
1 1 0 | 1 0 |
1 1 1 | 1 1 |
x
+ y
+ Cin
───
Cout S
FA
x
y
Cin
S
Cout
| | | y | ||
| |||||
| | 0 | 1 | 0 | 1 |
x | 1 | 0 | 1 | 0 | |
| | Cin | | ||
| | ||||
| | | y | ||
| |||||
| | 0 | 0 | 1 | 0 |
x | 0 | 1 | 1 | 1 | |
| | Cin | | ||
| | ||||
S = x'y'Cin+x'yCin'+xy'Cin'+xyCin = x ⊕ y ⊕ Cin
Cout = xy + xCin + yCin
48
Binary Adder
x
y
Cin
S
Cout
x
y
Cin
S
Cout
S = x'y'Cin+x'yCin'+xy'Cin'+xyCin = x ⊕ y ⊕ Cin
Cout = xy + xCin + yCin
49
Example 6
C3 C2 C1
c3 c2 c1 .
+ x3 x2 x1 x0
+ y3 y2 y1 y0
────────
C4 S3 S2 S1 S0
FA
x3 x2 x1 x0
FA
FA
FA
y3 y2 y1 y0
S3 S2 S1 S0
0
4-bit
Binary Adder
x3x2x1x0 y3y2y1y0
S3S2S1S0
C4
C4
Carry Propagate Adder
Or Ripple Carry Adder
0
0
50
Example 7
4-bit Ripple Carry Adder
A3 A2 A1 A0
B3 B2 B1 B0
S3 S2 S1 S0
C0
C4
x3 x2 x1 x0
y3 y2 y1 y0
x7 x6 x5 x4
y7 y6 y5 y4
S3 S2 S1 S0
S7 S6 S5 S4
4-bit Ripple Carry Adder
A3 A2 A1 A0
B3 B2 B1 B0
S3 S2 S1 S0
C0
C4
0
x3 x2 x1 x0
x7 x6 x5 x4
y3 y2 y1 y0
y7 y6 y5 y4
+
S3 S2 S1 S0
S7 S6 S5 S4
C8
51
Real Stuff
52
Binary Subtractors
53
Binary Subtractor
54
Binary Adder/Subtractor
55
Binary Adder/Subtractor
56
Exercise
57
Exercise - continued
58
Overflow Detection
59
Overflow
1 | 0 | 1 | 1 |
1 | 1 | 1 | 1 |
| | |
|
0
1
0
1
+
1
1
1
1
No space to
store!
60
Overflow
FA
x3 x2 x1 x0
FA
FA
FA
y3 y2 y1 y0
S3 S2 S1 S0
C4 C3 C2 C1
0
Overflow
0 0 1 1
1 0 0 1
+
1 1 0 0
0
0 1 1 1
1 1 0 1
+
0 1 0 0
1
61
Overflow
FA
x3 x2 x1 x0
FA
FA
FA
y3 y2 y1 y0
S3 S2 S1 S0
C4 C3 C2 C1
0
Overflow
62
Overflow
63
Multiplication and Division
64
Binary Multiplication
0 × 0 = 0
0 × 1 = 0
1 × 0 = 0
1 × 1 = 1
1 0 1
0 1 0
×
0 0 0
1 0 1
0 0 0
0
0
0
0 1 0 1 0
+
Multiplicand
Multiplier
Product
Partial Product
65
Multiplication by a Constant
X3 X2 X1 X0
1 0 1 ×
X3 X2 X1 X0
X3 X2 X1 X0 0 0
0 0 0 0 0
X0
X1
(X2+X0)
(X3+X1)
(X2+0)
(X3+0)
X2
X0
X3
X1
X2
0
X3
0
0
X0
X1
(X2+X0)
(X3+X1)
(X2+0)
(X3+0)
66
Multiplication by 2n
| | | |
| | | |
| | | |
1
0
1
0
1
0
1
0
1
1
0
0
0
0
x
x
3
6
12
×21
×21
×22
67
Division By 2n (Logical Right Shift)
| | | |
| | | |
| | | |
1
0
1
0
1
0
1
0
0
1
1
0
0
0
x
x
12
6
3
/21
/21
/22
68
Division By 2n (Arithmetic Right Shift)
| | | |
| | | |
| | | |
1
0
1
0
1
0
1
1
1
1
1
1
1
1
x
x
- 4
- 2
- 1
/21
/21
/22
69
Exercise
70
Number Width Expansion
71
Zero Fill
1 | 1 | 0 | 1 |
1 | 1 | 0 | 1 |
| | | |
0
0
0
0
13
13
72
Sign Extension
1 | 0 | 1 | 1 |
1 | 0 | 1 | 1 |
| | | |
1
1
1
1
0 | 0 | 1 | 1 |
0 | 0 | 1 | 1 |
| | | |
0
0
0
0
-5
-5
+3
+3
73
Exercises
74
Suggested Problems
75
Exercises
* | Obtain the 1’s and 2’s complements of the following binary numbers:
|
76
Exercises
* | Implement a full adder with two 4 × 1 multiplexers� |
77
Exercises
* | Convert decimal +61 and +27 to binary using the signed-2’s complement representation and enough digits to accommodate the numbers. Then perform the binary equivalent of (+27) + (– 61), (–27) + (+61) and (–27) + (–61). Convert the answers back to decimal and verify that they are correct. |
78
Exercises
* | The adder-subtractor circuit has the following values for mode input M and data inputs A and B. In each case, determine the values of the four SUM outputs and the carry C. M A B (a) 0 0111 0110�(b) 0 1000 1001�(c) 1 1100 1000�(d) 1 0101 1010�(e) 1 0000 0001 |
79