systems
play

Systems Addition and Subtraction in 1s and 2s Complement Form - PowerPoint PPT Presentation

Spring 2015 Week 9 Module 49 Digital Circuits and Systems Addition and Subtraction in 1s and 2s Complement Form Shankar Balachandran* Associate Professor, CSE Department Indian Institute of Technology Madras *Currently a Visiting


  1. Spring 2015 Week 9 Module 49 Digital Circuits and Systems Addition and Subtraction in 1’s and 2’s Complement Form Shankar Balachandran* Associate Professor, CSE Department Indian Institute of Technology Madras *Currently a Visiting Professor at IIT Bombay

  2. Addition and Subtraction of Signed Numbers  We will have to come up with ideas for adding signed numbers  Subtraction is performed by negating the number (changing sign) followed by addition.       X Y X Y  Subtraction requires 2 operations: 1. Negation, and 2. Addition Addition and Subtraction 2

  3. Addition/Subtraction in Sign Magnitude Representation  Negation is trivial – just invert the sign bit (MSB)  Addition is relatively complex because sign bits and relative magnitudes must be compared to perform operation. Addition and Subtraction 3

  4. Addition in 1’s Complement Representation Addition is performed in 2 steps:  Add all bits; any carry out of bit position i must be added into bit position 1. ( i +1). Add the result of first step with the carry out of the MSB position from 2. step 1. This carry is called the End Around Carry ( EAC ). Example s:  1111 (0) 0000 (0) 0000 + 0010 (2) + 1100 (-3) - 0011 10001 01100 + 1 + 0 0010 (2) 1100 (-3) Addition and Subtraction 4

  5. Subtraction in 1’s Complement Representation First negation  Trivial, flip all the bits  Then perform addition as shown earlier  Addition and Subtraction 5

  6. Examples of 1’s complement addition   – 5 ( ) + 5 0 1 0 1 1 0 1 0 ( ) + + 2 + 0 0 1 0 + ( ) + 2 + 0 0 1 0   ( ) + 7 0 1 1 1 - 3 1 1 0 0   ( ) + 5 0 1 0 1 – 5 1 0 1 0     + 2 – + 1 1 0 1 + 2 + 1 1 0 1 –   ( ) + 3 1 0 0 1 0 – 7 1 0 1 1 1 1 1 0 0 1 1 1 0 0 0

  7. Addition in 2’s Complement Representation Addition is performed by adding all bits; any carry out of bit position i  must be added into bit position ( i +1). Ignore carry out of MSB . Example s:  1111 (-1) 0000 (0) 0000 + 0010 (2) + 1101 (-3) - 0011 10001 01101 0001 (1) 1101 (-3) Addition and Subtraction 7

  8. Examples of 2’s complement addition   ( ) + 5 0 1 0 1 – 5 1 0 1 1 + ( + 2 ) + + ( + 2 ) + 0 0 1 0 0 0 1 0   ( + 7 ) – 3 0 1 1 1 1 1 0 1   ( ) + 5 0 1 0 1 – 5 1 0 1 1     + + + + – 2 1 1 1 0 – 2 1 1 1 0   ( + 3 ) – 7 1 0 0 1 1 1 1 0 0 1 ignore ignore

  9. Subtraction in 2’s Complement Representation Negation is expensive – first invert all bits; then add 1 .  Addition is performed by adding all bits; any carry out of bit position i  must be added into bit position ( i +1). Ignore carry out of MSB . Addition and Subtraction 9

  10. ( + 5 ) 0 1 0 1 0 1 0 1 – ( + 2 ) – 0 0 1 0 + 1 1 1 0 ( + 3 ) 1 0 0 1 1 ignore Examples of 2’s   1 0 1 1 1 0 1 1 – 5 complement ( ) – + 2 – 0 0 1 0 + 1 1 1 0 subtraction.   1 1 0 0 1 – 7 ignore ( + 5 ) 0 1 0 1 0 1 0 1   – – 2 – 1 1 1 0 + 0 0 1 0 ( + 7 ) 0 1 1 1   – 5 1 0 1 1 1 0 1 1   – – 2 – 1 1 1 0 + 0 0 1 0   1 1 0 1 – 3

  11. Overflow Detection  Some additions and subtractions may produce results that cannot be represented using the number of bits allocated for the result (i.e., precision).  For example, for an n - bit 2’s complement represented number, if the result is greater than ( 2 n-1 - 1 ) it can’t be represented using n -bits.  There is an overflow .  How can overflow be detected?  If (carry into the MSB) ≠ (carry out of the MSB) then overflow has occurred.  Examples : for 1’s comp. numbers 1011 (-4) for 2’s comp. numbers + 1010 (-5) 0100 0100 (4) 10101 - 1011 + 0101 (-5) + 1 1001 (-7) OVFL 0110 (6) OVFL Addition and Subtraction 11

  12. y y y n 1 – 1 0 Add  Sub control x x x n 1 – 1 0 c c n -bit adder 0 n s s s n 1 – 1 0 Adder/subtractor unit.

  13. End of Week 9: Module 49 Thank You Addition and Subtraction 13

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