Binary Addition Binary Multiplication
-
Upload
yuli-avery -
Category
Documents
-
view
66 -
download
2
description
Transcript of Binary Addition Binary Multiplication
![Page 1: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/1.jpg)
Binary AdditionBinary Multiplication
Section 4.5 and 4.7
![Page 2: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/2.jpg)
Topics
• Calculations Examples–Signed Binary Number–Unsigned Binary Number
• Hardware Implementation• Overflow Condition• Multiplication
![Page 3: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/3.jpg)
Unsigned Number
Decimal b1 b0
0 0 0
1 0 1
2 1 0
3 1 1
(2-bit example)
![Page 4: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/4.jpg)
Unsigned Addition
• 1+2=
Decimal b1 b0
0 0 0
1 0 1
2 1 0
3 1 1
Decimal b1
b0
1 0 1
+ 2 1 0
3 1 1
![Page 5: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/5.jpg)
Unsigned Addition
• 1+3=
Decimal b1 b0
0 0 0
1 0 1
2 1 0
3 1 1
Decimal b1
b0
1 1
1 0 1
+ 3 1 1
4 1 0 0
(Carry Out)
(Indicates Overflow)
![Page 6: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/6.jpg)
Unsigned Subtraction (1)
• 1-2=
Decimal b1 b0
0 0 0
1 0 1
2 1 0
3 1 1
Decimal b1
b0
1 0 1
+ -2 1 0
1 1
0 0
-1 0 1
(1’s complement)
(2’s complement)
![Page 7: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/7.jpg)
Unsigned Subtraction (2)
• 2-1=
Decimal b1 b0
0 0 0
1 0 1
2 1 0
3 1 1
Decimal b1 b0
1
2 1 0
+ -1 1 1
3 1 0 1
![Page 8: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/8.jpg)
Summary for Unsigned Addition/Subtraction
• Overflow can be an issue in unsigned addition
• Unsigned Subtraction (M-N)– If M≥N, and end carry will be
produced. The end carry is discarded.– If M<N, • Take the 2’s complement of the sum• Place a negative sign in front
![Page 9: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/9.jpg)
Signed Binary Numbers
• 4-bit binary number– 1 bit is used as a signed bit – -8 to +7– 2’s complement
![Page 10: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/10.jpg)
Signed Addition (70+80)b7 b6 b5 b4 b3 b2 b1 b0
0 1
70 0 1 0 0 0 1 1 0
80 0 1 0 1 0 0 0 0
1 0 0 1 0 1 1 0
70=21+22+26=2+4+6480=24+26=16+64
10010110→01101001 →0110101021+23+25+26=2+8+32+64=106
10010110↔-106
(Indicates a negative number)
010010110
010010110↔ 21+22+24+27=2+4+16+128=150
Conclusion: There is a problem of overflowFix: Use the end carry as the sign bit, and let b7 bethe extra bit.
![Page 11: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/11.jpg)
Signed Subtraction (70-80)b7 b6 b5 b4 b3 b2 b1 b0
70 0 1 0 0 0 1 1 0
-80 1 0 1 1 0 0 0 0
1 1 1 1 0 1 1 0
70=21+22+26=2+4+6480=24+26=16+64
11110110→00001001 →0000101021+23=10
11110110↔-10
(Indicates a negative number)
(No Problem)
![Page 12: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/12.jpg)
Signed Subtraction (-70-80)b7 b6 b5 b4 b3 b2 b1 b0
1 0 1 1
-70 1 0 1 1 1 0 1 0
-80 1 0 1 1 0 0 0 0
0 1 1 0 1 0 1 0
70=21+22+26=2+4+6480=24+26=16+64
(Indicates a positive number! A negative number expected.)
101101010 →010010101 → 010010110
010010110 ↔21+22+24+27=2+4+16+128=150
101101010 ↔-150
Conclusion: There is a problem of overflowFix: Use the end carry as the sign bit, and let b7 bethe extra bit.
![Page 13: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/13.jpg)
Observations• Given the similarity between addition
and subtraction, same hardware can be used.
• Overflow is an issue that needs to be addressed in the hardware implementation
• A signed number is not processed any different from an unsigned number. The programmer must interpret the results of addition and subtraction appropriately.
![Page 14: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/14.jpg)
Four-Bit Adder-Subtractor
![Page 15: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/15.jpg)
The Mode Input (1)
B0
If M=0, = If M=1, =
![Page 16: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/16.jpg)
The Mode Input (2)
If M=0, If M=1,
![Page 17: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/17.jpg)
M=0
0
B3 B2 B1 B0
![Page 18: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/18.jpg)
M=1
1
2’s complement is generated of B is generated!
![Page 19: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/19.jpg)
Unsigned Addition
When two unsigned numbers are added, an overflow is detected from the end carry.
![Page 20: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/20.jpg)
Detect Overflow in Signed Addition
Observe1. The cary into the sign bit2. The carry out of the sign bit
If they are not equal, they indicate an overflow.
![Page 21: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/21.jpg)
Two-Bit Binary Multiplier
(multiplicand)
(multiplier)
![Page 22: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/22.jpg)
𝐴 0𝐵00 0 0
0 1 0
1 0 0
1 1 1
Use an AND gate to multiply A0 and B0
![Page 23: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/23.jpg)
Hardware Correlation
![Page 24: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/24.jpg)
A Four-Bit Adder
![Page 25: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/25.jpg)
Four-bit by three-bit Binary Multiplier
B3 B2 B1 B0
A2 A1 A0
0 A0B3 A0B2 A0B1 A0B0
A1B3 A1B2 A1B1 A1B0
C14 S13 S12 S11 S10
A2B3 A2B2 A2B1 A2B0
C6 C5 C4 C3 C2 C1 C0
S10=A0B1+A1B0S11=A0B2+A1B1+C1S12=A0B3+A1B2+C2S13=0+A1B3+C3
(S1X, where 1 is the first 4-bit adder)
![Page 26: Binary Addition Binary Multiplication](https://reader035.fdocuments.us/reader035/viewer/2022081504/5681376e550346895d9f0791/html5/thumbnails/26.jpg)
Four-bit by three-bit Binary Multiplier