Presentation is loading. Please wait.

Presentation is loading. Please wait.

Binary Addition Binary Multiplication Section 4.5 and 4.7.

Similar presentations


Presentation on theme: "Binary Addition Binary Multiplication Section 4.5 and 4.7."— Presentation transcript:

1 Binary Addition Binary Multiplication Section 4.5 and 4.7

2 Topics Calculations Examples – Signed Binary Number – Unsigned Binary Number Hardware Implementation Overflow Condition Multiplication

3 Unsigned Number Decimalb1b0 000 101 210 311 (2-bit example)

4 Unsigned Addition 1+2= Decimalb1b0 000 101 210 311 Decimalb1b1 b0b0 101 +210 311

5 Unsigned Addition 1+3= Decimalb1b0 000 101 210 311 Decimalb1b1 b0b0 11 101 +311 4100 (Carry Out) (Indicates Overflow)

6 Unsigned Subtraction (1) 1-2= Decimalb1b0 000 101 210 311 Decimalb1b1 b0b0 101 +-210 11 00 01 (1’s complement) (2’s complement)

7 Unsigned Subtraction (2) 2-1= Decimalb1b0 000 101 210 311 Decimalb1b0 1 210 +11 3101

8 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

9 Signed Binary Numbers 4-bit binary number – 1 bit is used as a signed bit – -8 to +7 – 2’s complement

10 Signed Addition (70+80) b7b7 b6b6 b5b5 b4b4 b3b3 b2b2 b1b1 b0b0 01 7001000110 8001010000 10010110 70=2 1 +2 2 +2 6 =2+4+64 80=2 4 +2 6 =16+64 10010110→01101001 →01101010 2 1 +2 3 +2 5 +2 6 =2+8+32+64=106 10010110↔-106 (Indicates a negative number) 010010110 010010110↔ 2 1 +2 2 +2 4 +2 7 =2+4+16+128=150 Conclusion: There is a problem of overflow Fix: Use the end carry as the sign bit, and let b7 be the extra bit.

11 Signed Subtraction (70-80) b7b7 b6b6 b5b5 b4b4 b3b3 b2b2 b1b1 b0b0 7001000110 -8010110000 11110110 70=2 1 +2 2 +2 6 =2+4+64 80=2 4 +2 6 =16+64 11110110→00001001 →00001010 2 1 +2 3 =10 11110110↔-10 (Indicates a negative number) (No Problem)

12 Signed Subtraction (-70-80) b7b7 b6b6 b5b5 b4b4 b3b3 b2b2 b1b1 b0b0 1011 -7010111010 -8010110000 01101010 70=2 1 +2 2 +2 6 =2+4+64 80=2 4 +2 6 =16+64 (Indicates a positive number! A negative number expected.) 101101010 →010010101 → 010010110 010010110 ↔2 1 +2 2 +2 4 +2 7 =2+4+16+128=150 101101010 ↔-150 Conclusion: There is a problem of overflow Fix: Use the end carry as the sign bit, and let b7 be the extra bit.

13 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.

14 Four-Bit Adder-Subtractor

15 The Mode Input (1)

16 The Mode Input (2)

17 M=0 0 B3B3 B2B2 B1B1 B0B0

18 M=1 1 2’s complement is generated of B is generated!

19 Unsigned Addition When two unsigned numbers are added, an overflow is detected from the end carry.

20 Detect Overflow in Signed Addition Observe 1.The cary into the sign bit 2.The carry out of the sign bit If they are not equal, they indicate an overflow.

21 Two-Bit Binary Multiplier (multiplicand) (multiplier)

22 000 010 100 111 Use an AND gate to multiply A 0 and B 0

23 Hardware Correlation

24 A Four-Bit Adder

25 Four-bit by three-bit Binary Multiplier B3B2B1B0 A2A1A0 0A0B3A0B2A0B1A0B0 A1B3A1B2A1B1A1B0 C14S13S12S11S10 A2B3A2B2A2B1A2B0 C6C5C4C3C2C1C0 S10=A0B1+A1B0 S11=A0B2+A1B1+C1 S12=A0B3+A1B2+C2 S13=0+A1B3+C3 (S1X, where 1 is the first 4-bit adder)

26 Four-bit by three-bit Binary Multiplier


Download ppt "Binary Addition Binary Multiplication Section 4.5 and 4.7."

Similar presentations


Ads by Google