Professional Documents
Culture Documents
ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 1 ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 2
One Option: The Signed-Magnitude Representation What Happened to the Last Bit Pattern?
But we can use another bit for a sign: Signed-magnitude was used in some early
0 → +, and 1 → – computers (such as the IBM 704 in 1954).
ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 3 ECE 120: Introduction to Computing © 2016-2017 Steven S. Lumetta. All rights reserved. slide 4
1
1/18/2019
Signed-Magnitude Has Two Patterns for Zero How Do We Choose Among Representations?
There are two bit patterns for 0! What makes a representation good?
0 00000…00000 +0 ◦ efficient: most bit patterns represent some
item uniquely (so, not unary! )
1 00000…00000 -0 ◦ easy/fast implementation of common
This aspect made some hardware more operations: such as arithmetic for numbers
complex than is necessary.
◦ shared implementation with other
Modern machines do not use signed- representations: in this case,
magnitude. implementation is “free” in some sense
ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 5 ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 6
Representations Can be Chosen to Share Hardware Add Unsigned Bit Patterns Using Base 2 Addition
Imagine a device that performs addition on two Recall that the unsigned representation is
bit patterns of an unsigned representation. drawn from base 2.
0
“2” 1 We use base 2 addition for unsigned patterns.
0 unsigned 1 ◦ Like base 10, we
0 “5” add digit by digit. A B Sum
0 adder 1
“3” 1 ◦ Unlike base 10, the 0 0 0
1 single-digit table of 0 1 1
Can we use the same “adder” device for signed sums is quite small…
numbers? Yes! If we choose the right 1 0 1
◦ What is 1 + 1 + 1? 11
representations. 1 1 10
ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 7 ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 8
2
1/18/2019
Example: Addition of Unsigned Bit Patterns Overflow Can Occur with Unsigned Addition
Let’s do an example with 5-bit unsigned The unsigned representation is fixed width.
11 ◦ If we start with N bits,
01110 (14) ◦ we must end with N bits.
+ 00100 (4) What is the condition under which the sum
10010 (18) cannot be represented?
◦ The sum should have a 1 in the 2N place.
Good, we got the right answer!
◦ Only occurs when the most significant bits
of the addends generate a carry.
We call this condition an overflow.
ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 9 ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 10
ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 11 ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 12
3
1/18/2019
Unsigned Addition is Always Correct Mod 2N Modular Arithmetic Key to Good Integer Representations
ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 13 ECE 120: Introduction to Computing © 2016 Steven S. Lumetta. All rights reserved. slide 14