Uploaded by amuelsangels

CH05 - Computer Arithmetic

advertisement
+
William Stallings
Computer Organization
and Architecture
9th Edition
+
Computer Arithmetic
+
Arithmetic & Logic Unit (ALU)

Part of the computer that actually performs arithmetic and
logical operations on data

All of the other elements of the computer system are there
mainly to bring data into the ALU for it to process and then to
take the results back out

Based on the use of simple digital logic devices that can store
binary digits and perform simple Boolean logic operations
ALU Inputs and Outputs
+
Integer Representation

In the binary number system arbitrary numbers can be
represented with:

The digits zero and one

The minus sign (for negative numbers)

The period, or radix point (for numbers with a fractional
component)

For purposes of computer storage and processing we do not
have the benefit of special symbols for the minus sign and
radix point

Only binary digits (0,1) may be used to represent numbers
Figure 3-6
Taxonomy of integers
+
7
Representation of negative
numbers
 Is
a representation of negative numbers
possible?
 Unfortunately:
 you can not just stick a negative sign in front of a binary
number. (it does not work like that)
 There
are three methods used to represent
negative numbers.
 Signed
magnitude notation
 One’s complement and
 Two’s complement notation
+
8
Binary numbers

Binary number is simply a number comprised of only 0's and 1's.

Computers use binary numbers because it's easy for them to

You can express any base 10 (our number system -- where each digit is
between 0 and 9) with binary numbers.

The need to translate decimal number to binary and binary to decimal.

There are many ways in representing decimal number in binary numbers.
communicate using electrical current -- 0 is off, 1 is on.
+
9
How does the binary system work?

It is just like any other system

In decimal system the base is 10


We have 10 possible values 0-9
In binary system the base is 2


We have only two possible values 0 or 1.
The same as in any base, 0 digit has non contribution, where 1’s
has contribution which depends at there position.
+
10
Unsigned Representation

Represents positive integers.

Unsigned representation of 157:

position
7
6
5
4
3
2
1
0
Bit pattern
1
0
0
1
1
1
0
1
contribution
27
24
23
22
Addition is simple:
1 0 0 1 + 0 1 0 1 = 1 1 1 0.
20
+ Advantages and disadvantages of unsigned
notation


Advantages:

One representation of zero

Simple addition
Disadvantages

Negative numbers can not be represented.

The need of different notation to represent negative numbers.
11
+
12
Signed Magnitude Representation

Unsigned: - and + are the same.

In signed magnitude


the left-most bit represents the sign of the integer.

0 for positive numbers.

1 for negative numbers.
The remaining bits represent to magnitude of the numbers.
+
13
Example

Suppose 10011101 is a signed magnitude representation.

The sign bit is 1, then the number represented is negative
position
7
6
5
4
3
2
1
0
Bit pattern
1
0
0
1
1
1
0
1
24
23
22
contribution
-

The magnitude is 0011101 with a value 24+23+22+20= 29

Then the number represented by 10011101 is –29.
20
+
14
Exercise 1
1.
3710 has 0010 0101 in signed magnitude notation. Find
the signed magnitude of –3710 ?
2.
Using the signed magnitude notation find the 8-bit
binary representation of the decimal value 2410 and 2410.
3.
Find the signed magnitude of –63 using 8-bit binary
sequence?
+
15
Disadvantage of Signed Magnitude
 Addition
and subtractions are difficult.
 Signs
and magnitude, both have to carry out
the required operation.
 They are two representations of 0
 00000000 = + 010
 10000000 = - 010
 To test if a number is 0 or not, the CPU will need to see
whether it is 00000000 or 10000000.
 0 is always performed in programs.

Therefore, having two representations of 0 is inconvenient.
+
16
Signed-Summary
 In




signed magnitude notation,
The most significant bit is used to represent the sign.
1 represents negative numbers
0 represents positive numbers.
The unsigned value of the remaining bits represent The
magnitude.
 Advantages:
 Represents positive and negative numbers
 Disadvantages:
 two representations of zero,
 Arithmetic operations are difficult.
One’s Complement
• Method: Invert the ones and zeros
• 1110 = 00001011
• -1110 = 11110100
• 0 in MSB implies positive
• 1 in MSB implies negative
Sign-Magnitude Representation
There are several alternative
conventions used to represent
negative as well as positive
integers
•All of these alternatives involve treating the
most significant (leftmost) bit in the word as a
sign bit
•If the sign bit is 0 the number is positive
•If the sign bit is 1 the number is negative
Sign-magnitude representation is
the simplest form that employs a
sign bit
Drawbacks:
Because of these drawbacks,
sign-magnitude representation is
rarely used in implementing the
integer portion of the ALU
•Addition and subtraction require a
consideration of both the signs of the
numbers and their relative magnitudes to
carry out the required operation
•There are two representations of 0
+
Twos Complement Representation

Uses the most significant bit as a sign bit

Differs from sign-magnitude representation in the way that the
other bits are interpreted
Table 10.1 Characteristics of Twos Complement Representation and Arithmetic
Table 10.2
Alternative Representations for 4-Bit Integers
Addition
Overflow
OVERFLOW RULE:
+
If two numbers are added,
and they are both positive
or both negative, then
overflow occurs if and
only if the result has the
opposite sign.
Rule
Geometric Depiction of Twos
Complement Integers
+ Signed binary numbers
24
Possible representations:

Sign Magnitude:
One's Complement
000 = +0
001 = +1
010 = +2
011 = +3
100 = -0
101 = -1
110 = -2
111 = -3
Two's Complement
000 = +0
001 = +1
010 = +2
011 = +3
100 = -3
101 = -2
110 = -1
111 = -0

Issues: balance, number of zeros, ease of operations

Which one is best? Why?
TU/e Processor Design 5Z032
000 = +0
001 = +1
010 = +2
011 = +3
100 = -4
101 = -3
110 = -2
111 = -1
Two’s
complement
+
(let’s restrict to 4 bits)
25
0000
1111
1110
0001
-1
15
-2
0
1
0010
2
14
1101
1100
1011
-3
3
13
positive
-4 12
4
negative
-5
0100
11
5
10
-6
1010
1001
9
-7
6
8
-8
1000
TU/e Processor Design 5Z032
0011
0110
7
0111
0101
Two’s complement
26
3+2=5
0000
1111
1110
0001
-1
15
-2
0
1
0010
2
14
1101
1100
1011
-3
3
13
positive
-4 12
4
negative
-5
0100
11
5
10
-6
1010
1001
9
-7
6
8
-8
1000
TU/e Processor Design 5Z032
0011
0110
7
0111
0101
Two’s complement
27
3+ (-5) = -2
0000
1111
1110
0001
-1
15
-2
0
1
0010
2
14
1101
1100
1011
-3
3
13
positive
-4 12
4
negative
-5
0100
11
5
10
-6
1010
1001
9
-7
6
8
-8
1000
TU/e Processor Design 5Z032
0011
0110
7
0111
0101
Two’s complement
28
3+6 = -7 !!
overflow
0000
1111
1110
0001
-1
15
-2
0
1
0010
2
14
1101
1100
1011
-3
3
13
positive
-4 12
4
negative
-5
0100
11
5
10
-6
1010
1001
9
-7
6
8
-8
1000
TU/e Processor Design 5Z032
0011
0110
7
0111
0101
Two’s complement
29
-3 + (-6) = 7 !!
overflow
0000
1111
1110
0001
-1
15
-2
0
1
0010
2
14
1101
1100
1011
-3
3
13
positive
-4 12
4
negative
-5
0100
11
5
10
-6
1010
1001
9
-7
6
8
-8
1000
TU/e Processor Design 5Z032
0011
0110
7
0111
0101
+
30
Exercise 1
Let the decimal numbers A=54, B= -77, give their 8-bit 2’s
complement representation?
1.
Compute A + B in 2’s complement
2.
Compute A-B in 2’s complement, is it overflow? Why or
why not?
Using 8-bit 2's complement representation of negative
numbers, perform the following computations:
(i) - 35 + (-11)
(ii) 19 - (- 4)
Summary
+
Computer
Arithmetic
Chapter 10

Integer arithmetic

ALU

Negation

Integer representation

Addition and subtraction

Multiplication

Division



Sign-magnitude
representation
Twos complement
representation

Floating-point arithmetic

Range extension

Addition and subtraction

Fixed-point representation

Multiplication and division
Floating-point representation

Precision consideration

IEEE standard for binary
floating-point arithmetic

Principles

IEEE standard for binary
floating-point representation
Download