Binary additon subtraction 91509 L 15 Decoders Multiplexers
Binary additon & subtraction 9/15/09 - L 15 Decoders, Multiplexers Copyright 2009 - Joanne De. Groat, ECE, OSU 1
Class 18 – Subtraction o Binary Addition and Subtraction circuits Incrementer, Decrementer o Material from section 4 -3 and 4 -4 of text o o 9/15/09 - L 15 Decoders, Multiplexers Copyright 2009 - Joanne De. Groat, ECE, OSU 2
Binary Subtraction o o Have previously looked at the subtraction operation. A quick review. Just like subtraction in any other base n n n Minuend Subtrahand Difference 10110 - 100100 o And when a borrow is needed. Note that the borrow gives us 2 in the current bit position. o . 9/15/09 - L 15 Decoders, Multiplexers Copyright 2009 - Joanne De. Groat, ECE, OSU 3
And a full example o And more ripple - 9/15/09 - L 15 Decoders, Multiplexers Copyright 2009 - Joanne De. Groat, ECE, OSU 4
In General o When there is no borrow into the msb position, then the subtrahend in not larger than the minuend and the result is positive and correct. o If a borrow into the msb does occur, then the subtrahend is larger than the minuend. This was seen back in lecture 2. 9/15/09 - L 15 Decoders, Multiplexers Copyright 2009 - Joanne De. Groat, ECE, OSU 5
Consider o Now do the operation 4 – 6 o Correct difference is -2 or -0010 Different because 2 n was brought in and made the operation M-N+2 n o 9/15/09 - L 15 Decoders, Multiplexers Copyright 2009 - Joanne De. Groat, ECE, OSU 6
Desired o o o Actual desired magnitude is N-M To get this need to do 2 n – (M-N+2)= N-M Doing the subtraction from 2 n gives the correct result. 9/15/09 - L 15 Decoders, Multiplexers Copyright 2009 - Joanne De. Groat, ECE, OSU 7
Two’s compliment o o o But how do you represent a minus sign electronically in a computer? How can you represent it such that arithmetic operations are manageable? There are two types of compliments for each number base system. n n o Have the r’s complement Have the (r-1)’s complement For base 2 have 2’s complement 1’s complement 9/15/09 - L 15 Decoders, Multiplexers Copyright 2009 - Joanne De. Groat, ECE, OSU and 8
1’s Complement o 1’s complement of N is defined as (2 n -1)-N. n o o If n=4 have (2 n -1) being 1 0000 - 1 = 1111 So for n=4 would subtract any 4 -bit binary number from 1111. This is just inverting each bit. Example: 1’s compliment of 1011001 is 0100110 9/15/09 - L 15 Decoders, Multiplexers Copyright 2009 - Joanne De. Groat, ECE, OSU 9
2’s complement o o o The 2’s complement is defined as 2 n-N Can be done by subtraction of N from 2 n or adding 1 to the 1’s complement of a number. For 6 = 0110 n n The 1’s complement is 1001 The 2’s complement is 1010 9/15/09 - L 15 Decoders, Multiplexers Copyright 2009 - Joanne De. Groat, ECE, OSU 10
Operation with 2’s complement o o Add 4 and -6 Will use the 2’s complement of -6 or 1010 n n 4 -6 n o 0100 1010 1110 And taking the 2’s complement of 1110 get 0001 + 1 = 0010 9/15/09 - L 15 Decoders, Multiplexers Copyright 2009 - Joanne De. Groat, ECE, OSU 11
A 2’s complement table for 4 bits o 9/15/09 - L 15 Decoders, Multiplexers Listing the values represented. Copyright 2009 - Joanne De. Groat, ECE, OSU 12
A circuit that does +/o o A general adder subtractor OP=0 for addition/ =1 for subtraction 9/15/09 - L 15 Decoders, Multiplexers Copyright 2009 - Joanne De. Groat, ECE, OSU 13
Another number format o Signed magnitude – use the MSB to indicate the sign. The remaining bits indicate the magnitude. 9/15/09 - L 15 Decoders, Multiplexers Copyright 2009 - Joanne De. Groat, ECE, OSU 14
Overflow o o When adding 2 n-bit numbers it is possilbe to get a n+1 bit result if there is a carry out. On paper it is easy just add another bit. In 2’s complement add a msb 0 for a positive or a msb 1 for a negative. In a computer the number of bits that can be used is fixed. 9/15/09 - L 15 Decoders, Multiplexers Copyright 2009 - Joanne De. Groat, ECE, OSU 15
Overflow indication. o o In 8 -bit 2’s complement notation the range that can be represented is -127 to +127. Then the operation to add +70 to +80 is n n o Carries +70 +80 +150 0 100 0110 0 101 0000 1 001 0110 Also look at the addition of -70 and -80 9/15/09 - L 15 Decoders, Multiplexers Copyright 2009 - Joanne De. Groat, ECE, OSU 16
The other addition o The addition of -70 and -80 n n Carries -70 -80 -150 1 011 1010 1 011 0000 0 110 1010 o The rule – if the carry into the msb position differs from the carry out from the msb position then an overflow has occurred. The circuit o . o 9/15/09 - L 15 Decoders, Multiplexers Copyright 2009 - Joanne De. Groat, ECE, OSU 17
Class 18 assignment o o Covered sections 4 -3 through 4 -4 Problems for hand in n o Problems for practice n o none 4 -3, 4, 5, 6, 7, 8, 16 Reading for next class: sections 5 -1, 5 -2 9/15/09 - L 15 Decoders, Multiplexers Copyright 2009 - Joanne De. Groat, ECE, OSU 18
- Slides: 18