0% found this document useful (0 votes)
3 views

CH08.2-Computer Arithmetic

The document discusses computer arithmetic, focusing on the Arithmetic & Logic Unit (ALU) and various methods of integer representation, including sign-magnitude and two's complement. It also covers floating-point representation, its principles, and the IEEE 754 standard for binary floating-point arithmetic. Key topics include negation, overflow, and precision considerations in arithmetic operations.

Uploaded by

Minh Duy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

CH08.2-Computer Arithmetic

The document discusses computer arithmetic, focusing on the Arithmetic & Logic Unit (ALU) and various methods of integer representation, including sign-magnitude and two's complement. It also covers floating-point representation, its principles, and the IEEE 754 standard for binary floating-point arithmetic. Key topics include negation, overflow, and precision considerations in arithmetic operations.

Uploaded by

Minh Duy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

+ 2

William Stallings + Chapter 8.2


Computer Organization
and Architecture Computer Arithmetic
10th Edition

+ 3 4

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

1
+ 5
Sign-Magnitude Representation
6

Integer Representation
There are several alternative •All of these alternatives involve treating the
most significant (leftmost) bit in the word as a
 In the binary number system arbitrary numbers can be conventions used to represent sign bit
negative as well as positive •If the sign bit is 0 the number is positive
represented with: integers •If the sign bit is 1 the number is negative

 The digits zero and one


Sign-magnitude representation is
 The minus sign (for negative numbers) the simplest form that employs a
 The period, or radix point (for numbers with a fractional sign bit
component)
•Addition and subtraction require a
consideration of both the signs of the
 For purposes of computer storage and processing we do not Drawbacks: numbers and their relative magnitudes to
carry out the required operation
have the benefit of special symbols for the minus sign and •There are two representations of 0

radix point Because of these drawbacks,


sign-magnitude representation is
rarely used in implementing the
 Only binary digits (0,1) may be used to represent numbers integer portion of the ALU

7
Table 10.2 8
Alternative Representations for 4-Bit Integers

Table 10.1
Characteristics of Twos Complement Representation and Arithmetic

2
9
+ 10

Range Extension

 Range of numbers that can be expressed is extended by


increasing the bit length

 In sign-magnitude notation this is accomplished by moving


the sign bit to the new leftmost position and fill in with zeros

 This procedure will not work for twos complement negative


integers
 Rule is to move the sign bit to the new leftmost position and fill in
with copies of the sign bit
 For positive numbers, fill in with zeros, and for negative numbers,
fill in with ones
 This is called sign extension

11
+ 12

Fixed-Point Representation Negation


 Twos complement operation
 Take the Boolean complement of each bit of the integer
(including the sign bit)
 Treating the result as an unsigned binary integer, add 1
Programmer can use the
same representation for +18 = 00010010 (twos complement)
The radix point (binary point) binary fractions by scaling bitwise complement = 11101101
is fixed and assumed to be to the numbers so that the + 1
the right of the rightmost digit binary point is implicitly
positioned at some other 11101110 = -18
location
 The negative of the negative of that number is itself:

-18 = 11101110 (twos complement)


bitwise complement = 00010001
+ 1
00010010 = +18

3
+ 13
+ 14

Negation Special Case 1 Negation Special Case 2

0 = 00000000 (twos complement) -128 = 10000000 (twos complement)

Bitwise complement = 01111111


Bitwise complement = 11111111
Add 1 to LSB + 1
Add 1 to LSB + 1
Result 10000000
Result 100000000
So:

-(-128) = -128 X
Overflow is ignored, so:
Monitor MSB (sign bit)
-0=0
It should change during negation

15 16

Overflow

OVERFLOW RULE:

If two numbers are added,


Rule
and they are both positive
or both negative, then
+ overflow occurs if and
only if the result has the
opposite sign.

4
17 18

Subtraction

SUBTRACTION RULE:

To subtract one number


(subtrahend) from Rule

another (minuend), take


+
the twos complement
(negation) of the
subtrahend and add it
to the minuend.

19 20

5
21 22

23 24

6
25 26

27 28

7
29 30

31
+ 32

Floating-Point Representation
Principles
 With a fixed-point notation it is possible to represent a range
of positive and negative integers centered on or near 0

 By assuming a fixed binary or radix point, this format allows


the representation of numbers with a fractional component as
well

 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

8
33
+ 34

Floating-Point
Significand
 The final portion of the word

 Any floating-point number can be expressed in many ways

The following are equivalent, where the significand is


expressed in binary form:
0.110 * 25
110 * 22
0.0110 * 26

 Normal number
 The most significant digit of the significand is nonzero

35 36

9
IEEE Standard 754 37
+ 38

IEEE 754-2008
Standard was developed to
facilitate the portability of  Defines the following different types of floating-point formats:
programs from one Arithmetic format
Most important floating-point 
processor to another and to
representation is defined  All the mandatory operations defined by the standard are supported
encourage the development by the format. The format may be used to represent floating-point
of sophisticated, numerically operands or results for the operations described in the standard.
oriented programs
 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
Standard has been widely implemented in any conforming implementation.
adopted and is used on IEEE 754-2008 covers both
 Interchange format
virtually all contemporary binary and decimal floating-
processors and arithmetic point representations  A fully specified, fixed-length binary encoding that allows data
interchange between different platforms and that can be used for
coprocessors storage.

39 40
Table 10.3 IEEE 754 Format Parameters

* not including implied bit and not including sign bit

10
+ Additional Formats 41 42

Table 10.4
Extended Precision Formats IEEE Formats
Extendable Precision Format
 Provide additional bits in the exponent
(extended range) and in the significand
(extended precision)  Precision and range are defined
under user control
 Lessens the chance of a final result that
has been contaminated by excessive  May be used for intermediate
roundoff error calculations but the standard
places no constraint or format or
 Lessens the chance of an intermediate length
overflow aborting a computation whose
final result would have been
representable in a basic format

 Affords some of the benefits of a larger


basic format without incurring the time
penalty usually associated with higher
precision

Table 10.5 43 44

Interpretation of IEEE 754 Floating-Point Numbers (page 1 of 3) Table 10.5


Interpretation of IEEE 754 Floating-Point Numbers (page 2 of 3)

(a) binary32 format (a) binary64 format

11
45 46
Table 10.5
Interpretation of IEEE 754 Floating-Point Numbers (page 3 of 3)

(a) binary128 format

47 48

12
49 50

+ 51
+ 52

Precision Considerations Interval Arithmetic


Rounding  Provides an efficient method for  Minus infinity and rounding
monitoring and controlling errors in
floating-point computations by to plus are useful in
 IEEE standard approaches: producing two values for each result implementing interval
arithmetic
The two values correspond to the
 Round to nearest: 
lower and upper endpoints of an
 The result is rounded to the nearest representable
number.
interval that contains the true result
Truncation
 The width of the interval indicates
 Round toward +∞ : the accuracy of the result  Round toward zero
 The result is rounded up toward plus infinity.  If the endpoints are not
representable then the interval
 Extra bits are ignored
 Round toward -∞: endpoints are rounded down and up
respectively  Simplest technique
 The result is rounded down toward negative infinity.
 Round toward 0:  If the range between the upper and  A consistent bias toward zero in
lower bounds is sufficiently narrow the operation
 The result is rounded toward zero. then a sufficiently accurate result has
 Serious bias because it affects
been obtained
every operation for which
there are nonzero extra bits

13
+ 53 Table 10.7 54

IEEE Standard for Binary Floating-Point Arithmetic Operations that Produce a Quiet NaN
Infinity

Is treated as the limiting case of real arithmetic, with the infinity


values given the following interpretation:

- ∞ < (every finite number) < + ∞

For example:
5 + (+ ∞ ) = + ∞ 5÷ (+ ∞ ) = +0
5 - (+ ∞ ) = - ∞ (+ ∞ ) + (+ ∞ ) =+∞
5 + (- ∞ ) = - ∞ (- ∞ ) + (- ∞) =-∞
5 - (- ∞ ) = + ∞ (- ∞ ) - (+ ∞ ) =-∞
5 * (+ ∞ ) = + ∞ (+ ∞ ) - (- ∞ ) =+∞

55
+ Summary
56

Computer
Arithmetic
Chapter 10
 Integer arithmetic
 ALU
 Negation
 Integer representation
 Addition and subtraction
 Sign-magnitude
 Multiplication
representation
 Division
 Twos complement
representation  Floating-point arithmetic
 Range extension  Addition and subtraction
 Fixed-point representation  Multiplication and division
 Floating-point representation  Precision consideration
 Principles  IEEE standard for binary
 IEEE standard for binary floating-point arithmetic
floating-point representation

14

You might also like