CH10-COA10e - Computer Arithmetic PDF
CH10-COA10e - Computer Arithmetic PDF
CH10-COA10e - Computer Arithmetic PDF
William Stallings
Computer Organization
and Architecture
10th Edition
© 2016 Pearson Education, Inc., Hoboken,
NJ. All rights reserved.
+ Chapter 10
Computer Arithmetic
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
+
Arithmetic & Logic Unit (ALU)
Based on the use of simple digital logic devices that can store
binary digits and perform simple Boolean logic operations
ALU
Operand Result
Registers Registers
There are several alternative •All of these alternatives involve treating the
most significant (leftmost) bit in the word as a
conventions used to represent sign bit
negative as well as positive •If the sign bit is 0 the number is positive
integers •If the sign bit is 1 the number is negative
Sign-magnitude representation is
the simplest form that employs a
sign bit
Expansion of Bit Length Add additional bit positions to the left and fill in with the value
of the original sign bit.
If two numbers with the same sign (both positive or both
Overflow Rule negative) are added, then overflow occurs if and only if the result
has the opposite sign.
Subtraction Rule To subtract B from A, take the twos complement of B and add it
to A.
–128 64 32 16 8 4 2 1
1 0 0 0 0 0 1 1
–128 +2 +1 = –125
–128 64 32 16 8 4 2 1
1 0 0 0 1 0 0 0
–120 = –128 +8
Add 1 to LSB + 1
Result 100000000
-0=0
Add 1 to LSB + 1
Result 10000000
So:
-(-128) = -128 X
0011 = 3 1100 = –4
+0100 = 4 +1111 = –1
0111 = 7 11011 = –5
(c) (+3) + (+4) (d) (–4) + (–1)
0101 = 5 1001 = –7
+0100 = 4 +1010 = –6
1001 = Overflow 10011 = Overflow
(e) (+5) + (+4) (f) (–7) + (–6)
OVERFLOW RULE:
SUBTRACTION RULE:
1011 = –5 0101 = 5
+1110 = –2 +0010 = 2
11001 = –7 0111 = 7
0111 = 7 1010 = –6
+0111 = 7 +1100 = –4
1110 = Overflow 10110 = Overflow
-9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 n–1 n–1
–2 2 –1
n–1 n–1
–2 –1 2
(a) 4-bit numbers (b) n-bit numbers
Complementer
SW
OF Adder
OF = overflow bit
SW = Switch (select addition or subtraction)
Shift Right
C An-1 A0 Qn-1 Q0
Multiplier
C A Q M
0 0000 1101 1011 Initial Values
C, A 0
M Multiplicand
Q Multiplier
Count n
No Yes
Q0 = 1?
C, A A+M
Shift right C, A, Q
Count Count – 1
No Yes
Count = 0? END Product
in A, Q
A 0, Q-1 0
M Multiplicand
Q Multiplier
Count n
= 10 Q0 , Q-1 = 01
= 11
= 00
A A–M A A+M
Arithmetic Shift
Right: A, Q, Q -1
Count Count – 1
No Yes
Count = 0? END
Fourth
0001 0101 0 0111 Shift
Cycle
1001 1001
´0011 (0) ´1101 (0)
00000111 1–0 00000111 1–0
0000000 1–1 1111001 0–1
111001 0–1 000111 1–0
11101011 (–21) 00010101 (21)
(c) (–7) ´ (3) = (–21) (d) (–7) ´ (–3) = (21)
A 0
M Divisor
Q Dividend
Count n
Shift Left
A, Q
A A–M
No Yes
A < 0?
Q0 0
Q0 1 A A+M
Count Count – 1
No Yes
Count = 0? END Quotient in Q
Remainder in A
Limitations:
Very large numbers cannot be represented nor can very small
fractions
The fractional part of the quotient in a division of two large
numbers could be lost
(a) Format
(b) Examples
Normal number
The most significant digit of the significand is nonzero
Number
–231 0 231 – 1 Line
Negative Positive
Underflow Underflow
Negative Expressible Negative Expressible Positive Positive
Overflow Numbers Numbers Overflow
Zero
Number
– (2 – 2–23) 2128 –2–127 0 2–127 (2 – 2–23) 2128 Line
Arithmetic format
All the mandatory operations defined by the standard are supported
by the format. The format may be used to represent floating-point
operands or results for the operations described in the standard.
Basic format
This format covers five floating-point representations, three binary
and two decimal, whose encodings are specified by the standard, and
which can be used for arithmetic. At least one of the basic formats is
implemented in any conforming implementation.
Interchange format
A fully specified, fixed-length binary encoding that allows data
interchange between different platforms and that can be used for
storage.
8 bits 23 bits
(a) binary32 format
sign biased
bit exponent
11 bits 52 bits
(b) binary64 format
sign
bit
biased
trailing significand field
exponent
15 bits 112 bits
(c) binary128 format
Format Type
Format
Arithmetic Format Basic Format Interchange Format
binary16 X
binary32 X X X
binary64 X X X
binary128 X X X
binary{k}
X X
(k = n ´ 32 for n > 4)
decimal64 X X X
decimal128 X X X
decimal{k}
X X
(k = n ´ 32 for n > 4)
extended precision X
extendable precision X
X = Xs ´ BXE ( )
X + Y = X s ´ B XE -YE + Ys ´ B YE üï
ý X E £ YE
Y = Ys ´ BYE ( )
X - Y = X s ´ B XE -YE - Ys ´ B YE ïþ
X ´ Y = ( X s ´ Ys ) ´ B
X E +YE
X æ Xs ö X -Y
= çç ÷÷ ´ B E E
Y è Ys ø
Examples:
X = 0.3 ´ 102 = 30
Y = 0.2 ´ 103 = 200
Yes No Exponent
RETURN underflow?
Shift
No significand
Significand Yes
right
=0?
Report
Yes underflow
Increment
exponent
Put other RETURN
number in Z
RETURN
Yes
Report Exponent No
overflow overflow?
RETURN
No No
X = 0? Y = 0? Add
Exponents
Yes Yes
Z 0 Subtract Bias
RETURN
Exponent Yes Report
Overflow? Overflow
No
No
Multiply
Significands
Normalize
Round RETURN
No No
X = 0? Y = 0? Subtract
Exponents
Yes Yes
Z 0 Z ∞ Add Bias
RETURN
Exponent Yes Report
Overflow? Overflow
No
No
Divide
Significands
Normalize
Round RETURN
(b) Binary example, with guard bits (d) Hexadecimal example, with guard bits
If the range between the upper and A consistent bias toward zero in
lower bounds is sufficiently narrow the operation
then a sufficiently accurate result has
been obtained Serious bias because it affects
every operation for which
there are nonzero extra bits
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
+
IEEE Standard for Binary Floating-Point Arithmetic
Infinity
For example:
5 + (+ ∞ ) = + ∞ 5÷ (+ ∞ ) = +0
5 - (+ ∞ ) = - ∞ (+ ∞ ) + (+ ∞ ) =+∞
5 + (- ∞ ) = - ∞ (- ∞ ) + (- ∞) =-∞
5 - (- ∞ ) =+∞ (- ∞ ) - (+ ∞ ) =-∞
5 * (+ ∞ ) = + ∞ (+ ∞ ) - (- ∞ ) =+∞
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Table 10.7
Operations that Produce a Quiet NaN
uniform
spacing