15
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text

Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text

Embed Size (px)

Citation preview

Page 1: Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text

Computer Organization

CS345David Monismith

Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text

Page 2: Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text

Review

• Last time we looked at several different representations of signed integers.

• We looked at signed binary numbers, where we used a leading zero or one to represent sign.

• We also looked at one's complement and two's complement numbers.

• This time – Review two's complement for the homework assignment.– Floating Point Representation

Page 3: Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text

Review 2’s Compliment

Two's complement numbers are used on most CPUs to represent signed integer values. Positive values are converted to negative values from regular sign and magnitude binary representation using the following method:1. bit flip2. add one to the result

Such values are converted back from negative to positive by undoing the operations above:3. subtract one from the two's complement representation of the negative

number4. bit flip the result

Page 4: Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text

Examples

• Using 5 bit binary numbers we may represent 10 as follows in signed magnitude representation:

01010 b = 10d• Notice that in the representation above we have four bits representing the value and

one bit (the leading zero) representing the sign (0 for positive and 1 for negative).• Performing a bit flip on 10d yields the following result:

10101b• Adding one yields the two's complement representation:

10110b = -10d (two's complement)• Notice that in the example above there is a leading one representing that the

number is negative.• All one's complement, two's complement, and signed magnitude binary numbers

have a leading zero or one to represent the value as positive or negative respectively.

Page 5: Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text

Five bit 2’s Compliment Numbers

00000b = 0d00001b = 1d 11111b = -1d00010b = 2d 11110b = -2d00011b = 3d 11101b = -3d00100b = 4d 11100b = -4d00101b = 5d 11011b = -5d00110b = 6d 11010b = -6d00111b = 7d 11001b = -7d01000b = 8d 11000b = -8d01001b = 9d 10111b = -9d01010b = 10d 10110b = -10d01011b = 11d 10101b = -11d01100b = 12d 10100b = -12d01101b = 13d 10011b = -13d01110b = 14d 10010b = -14d01111b = 15d 10001b = -15d

10000b = -16d

Page 6: Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text

Examples

• Examples of adding and subtracting these values follow below: 01010b = 10d +10110 = -10d-------------------------- 00000b = 0d • Subtraction or performing the operation a - b, can be represented as a + (-b).

Take 9 - 3 as an example. We first convert 3 to -3 and add -3 to 9 as follows: 01001b = 9d +11101 = -3d-------------------------- 00110b = 6d

Page 7: Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text

Examples

• Subtracting a negative number from another negative number is equally easy. We simply subtract one from the two's complement representation of the negative number and perform a bit flip.

• For example if we take -8 - (-4), the result should be -4. But to perform thisoperation as an addition, we need to convert -4 to +4.

• 11100b is the two's complement representation of -4.• 11100b - 1b = 11011b• Bit flipping 11011b yields 00100b = 4d• Notice that in the example above we pretend 11100 is an unsigned binary number

and subtract one.• Now, our result from -8 + 4 can be computed

11000b = -8d +00100 = 4d-------------------------- 11100b = -4d

Page 8: Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text

Floating Point Representation

• Representing real numbers in binary is quite simple and is not much different than converting from a decimal integer to binary.

• Consider 8.5d• Notice that a value such as 8 can be represented as an unsigned binary integer as

follows:1000b• Notice that values after the decimal point may be represented as a series of ones and

zeroes representing the following values:1/2, 1/4, 1/8, 1/16, 1/32, . . . Or2^-1, 2^-2, 2^-3, 2^-4, 2^-5, . . .

• Thus, we have the following binary to decimal relationships0.5d = 0.1b0.25d = 0.01b0.0125d = 0.001b. . .

Page 9: Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text

Floating Point Representation• Additionally, notice that we can convert from decimal to binary by iteratively multiplying decimal fractions

(values after the decimal point) by two until we reach a binary value. Notice that the values before the decimal point represent our binary fraction.

Consider 0.5d0.5d * 2----------- <-- binary "decimal" point1.0dResult is 0.1b = 2^-1 = 1/2 = 0.5d

Consider 0.25d

0.25d * 2-------------0.5d * 21.0dResult is 0.01b = 0 * 2^-1 + 1 * 2^-2 = 1/4 = 0.25d

Page 10: Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text

Floating Point Representation

• Consider 0.125d• 0.0125d * 2• -----------------• 0.25d * 2• 0.5d * 2• 1.0d• Result is 0.001b = 0 * 2^-1 + 0 * 2^-2 + 1 * 2^-3 = 1/8 = 0.125d• Consider another value such as 0.75d. A conversion to binary is performed as follows:• 0.75d * 2• -------------• 1.5d --> 0.5d*2 notice that we only multiply values after the decimal point by • 1.0d• Result is 0.11b = 1*2^-1 + 1*2^-2 = 1/2 + 1/4 = 3/4 = 0.75d

Page 11: Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text

Floating Point Representation• Now, lets look at 0.4d

0.4d * 2------------0.8d * 21.6d --> 0.6d * 21.2d --> 0.2d * 20.4d * 20.8d * 21.6d --> 0.6d * 21.2d --> 0.2d * 20.4d * 20.8d * 21.6d --> 0.6d * 21.2d --> 0.2d * 20.4d * 2 . . .

• Result is 0.0110011001100110011 . . .b = 0*2^-1 + 1*2^-2 + 1*2^-3 + 0*2^-4 + 0*2^-5 + 1*2^-6 + 1*2^-7 + 0*2^-8 + 0*2^-9 + 1*2^-10 . . .

Page 12: Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text

Floating Point Representation

• Notice that this result is an infinitely repeating series. Just like in decimal, where values such as 1/3 may only be displayed as a decimal expansion of an infinitely repeating series, binary expansions may result in infinitely repeating series.

• If we sum 10 bits from the results of the binary expansion of 0.4d, we can get an approximation for the value.

• Notice, 1/4 + 1/8 + 1/64 + 1/128 + 1/1024 = 0.39941406dThis is a near approximation to 0.4d

Page 13: Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text

Example

• Consider a number such as 123.45d123 % 2 = 161 % 2 = 130 % 2 = 015 % 2 = 17 % 2 = 13 % 2 = 11

0.45d * 2-----------0.9d * 21.8d --> 0.8d * 21.6d --> 0.6d * 21.2d --> 0.2d * 20.4d * 20.8d * 21.6d --> 0.6d * 21.2d --> 0.2d * 20.4d * 20.8d * 21.6d --> 0.6d * 21.2d --> 0.2d * 20.4d * 2 . . .

Now the result is: 1111011.0111001100110011 . . .

Page 14: Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text

IEEE Standard

• Again notice that we convert the values after the decimal point to binary by iteratively multiplying all digits after the decimal point by two.

• Notice that if we are going to convert this to a representation that the computer can understand, we will have to limit the precision or the number of bits after the decimal place.

• IEEE Standard 754 denotes the standard representation for floating point numbers. 32 bit floating point numbers are represented in binary scientific notation.

• Recall that decimal floating point numbers are represented as follows:

+/- x.xxxxx * 10 ^ +/- y• where x is the significand and y is the exponent.

Page 15: Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text

IEEE Standard

• In binary, we may represent scientific notation as:+/- x.xxxxxx * 2 ^ +/- y

sign-bit exponent significand1-bit 8-bit 23-bit

• The sign bit denotes whether the significand is positive or negative• The exponent is a biased binary number and may represent a value

between -126 and 127• The significand represents an unsigned binary value less than 2 decimal.

Notice that this value will always be greater than or equal to one unless it is zero. Therefore, we will ignore the leading one in the significand.

• Simply put, the significand denotes the significant bits of the value we are trying to represent.