addition and subtraction
play

Addition and Subtraction Philipp Koehn 4 September 2019 Philipp - PowerPoint PPT Presentation

Addition and Subtraction Philipp Koehn 4 September 2019 Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019 1 addition Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September


  1. Addition and Subtraction Philipp Koehn 4 September 2019 Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  2. 1 addition Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  3. 1-Bit Adder 2 • Let’s start simple: Adding two 1-Bit numbers • Truth table A B A+B 0 0 0 0 1 1 1 0 1 1 1 10 Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  4. Really 2 Operations 3 • Truth table for "position 0" bit A B A+B 0 0 0 xor 0 1 1 1 0 1 1 1 0 • Truth table for carry bit A B A+B carry 0 0 0 0 1 0 and 1 0 0 1 1 1 Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  5. Reminder: Basic Gates 4 AND OR NOT NAND NOR Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  6. Circuits 5 • "Position 0" bit A B OUT0 A OR 0 0 0 B xor OUT0 0 1 1 AND 1 0 1 NAND 1 1 0 • Carry bit A B OUTC 0 0 0 A and OUTC AND 0 1 0 B 1 0 0 1 1 1 Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  7. Putting them Together 6 A OR B OUT0 AND NAND CARRY AND Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  8. N-Bit Addition 7 011 +11 --- 110 --- 110 Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  9. N-Bit Addition 8 011 +11 --- 110 --- 110 1+1 = 0, carry the 1 Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  10. N-Bit Addition 9 011 +11 --- 110 --- 110 1+1+1 = 1, carry the 1 Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  11. N-Bit Addition 10 011 +11 --- 110 --- 110 copy carry bit Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  12. 1-Bit Adder 11 A OR B OUT0 AND NAND CARRY AND Our adder cannot handle carry as input yet Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  13. Half 1-Bit Adder 12 A OR B OUT0 AND NAND CARRY AND 1-BIT HALF ADDER Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  14. Building a 1-Bit Full Adder 13 SUM A S A 1-BIT HALF B CARRY ADDER B C Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  15. Building a 1-Bit Full Adder 14 CARRY SUM S A 1-BIT HALF A CARRY ADDER S B A C 1-BIT HALF B CARRY ADDER B C Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  16. Building a 1-Bit Full Adder 15 SUM CARRY S A 1-BIT HALF A ADDER S B A C 1-BIT CARRY HALF OR B ADDER B C Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  17. 1-Bit Full Adder 16 SUM CARRY S A 1-BIT HALF A ADDER S B A C 1-BIT CARRY HALF OR B ADDER B C 1-BIT FULL ADDER Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  18. N-Bit Full Adder 17 011 +11 --- 110 --- 110 Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  19. N-Bit Full Adder 18 B0 A0 011 +11 --- A B CI 110 1-BIT --- FULL 110 ADDER CO S SUM0 Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  20. N-Bit Full Adder 19 B1 B0 A1 A0 011 +11 --- A B CI A B CI 110 1-BIT 1-BIT --- FULL FULL 110 ADDER ADDER CO S CO S SUM1 SUM0 Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  21. N-Bit Full Adder 20 B2 B1 B0 A2 A1 A0 and so A B A B A B CI CI CI on 1-BIT 1-BIT 1-BIT ... FULL FULL FULL ADDER ADDER ADDER CO S CO S CO S SUM2 SUM1 SUM0 Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  22. 21 subtraction Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  23. First, a Trick 22 • Normally, we subtract like this: 0253 -176 ---- 0110 ---- 0077 Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  24. Computing the Inverse 23 • Now we use the inverse of the subtrahend 0999 -176 ---- 0823 Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  25. Subtraction by Addition 24 • This allows us to carry our subtraction by addition 00253 +0823 ----- 01076 • Well, with minor corrections 01076 +0001 -1000 ----- 0077 Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  26. Also Works in Binary 25 Original problem 00253 0011111101 -0176 -010110000 ----- ---------- 00077 0001001101 Inverse of subtrahend 00823 0001001111 Addition 00253 0011111101 +0823 +001001111 ----- ---------- 01076 0101001100 Corrections +0001 +000000001 -1000 -100000000 ---------- ---------- 0077 0001001101 Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  27. Start with N-Bit Adder 26 A0 A1 A2 A3 B0 B1 B2 B3 4-BIT CI CO FULL ADDER S0 S1 S2 S3 Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  28. Invert Bits of Subtrahend 27 B0 B1 B2 B3 A0 A1 A2 A3 B0 B1 B2 B3 4-BIT CI CO FULL ADDER S0 S1 S2 S3 Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  29. Add One 28 A0 A1 A2 A3 B0 B1 B2 B3 A0 A1 A2 A3 B0 B1 B2 B3 4-BIT V CI CO FULL ADDER S0 S1 S2 S3 Trick: add one as carry in Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  30. Invert Overflow --- DONE 29 A0 A1 A2 A3 B0 B1 B2 B3 A0 A1 A2 A3 B0 B1 B2 B3 4-BIT V CI CO FULL ADDER S0 S1 S2 S3 OVERFLOW SUM mm... Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  31. 30 unifying addition and subtraction machines Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  32. Goal 31 • Not two machines for addition and subtraction ⇒ Combined adder and subtractor • Input: A, B, and subtraction flag SUB • Output – if SUB=0: A+B – if SUB=1: A-B Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  33. NOT only if SUB 32 B0 B1 B2 B3 A0 A1 A2 A3 A0 A1 A2 A3 B0 B1 B2 B3 4-BIT V CI CO FULL ADDER S0 S1 S2 S3 OVERFLOW SUM mm... Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  34. NOT only if SUB 33 • Truth table SUB X OUT 0 0 0 0 1 1 1 0 1 1 1 0 • Looks like XOR XOR Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

  35. Combined Machine 34 A0 A1 A2 A3 B0 B1 B2 B3 SUB A0 A1 A2 A3 B0 B1 B2 B3 4-BIT SUB CI CO FULL ADDER SUB S0 S1 S2 S3 OVERFLOW SUM Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend