project3 - University of California, Santa Barbara

advertisement
ECE 15B
Spring 2010
University of California, Santa Barbara
ECE 15B COMPUTER ORGANIZATION
Project #3
Encoding Huge Numbers: IEEE 754 Single Precision (32-Bit) Floating-Point Standard
Due at 11:00 PM June 4, 2010
1. Introduction
In this project, you are to write function fpcode that takes in a real number is normalized decimal
scientific notation (already parsed) and will compute the IEEE 754 representation of the given
number. The function definition in C is:
void fpcode(int bit, int exponent, int mantissa)
where bit is 0 if the number is positive and 1 if the number is negative and the real number being
passed in through parsed fields is equal to:
-1(sign bit) * mantissa * 10exponent
2. Overview
A fixed-point number is a means to represent fractional numbers using a fixed number of bits,
essentially representing the fractional number as an integer scaled by a specific factor. For example,
the real number 1.23 can alternatively be expressed as 123/100, where the scaling factor is 100. For a
certain fixed-point type, the scaling factor is constant, thus limiting the representation of very large or
very small numbers. Also, fixed-point representation is prone to loss of precision when two large
numbers are divided. The fixed-point data type is widely used in digital signal processing (DSP) and
game applications, where performance is more important than precision.
Floating-point types, on the other hand, store the scaling factor as part of the value, allowing a wider
range of values that can be represented. Floating-point representation is essentially the same scientific
notation, where scientific notation represents numbers as a base number and an exponent.
Examples:
( a ) 123.456 in normalized scientific notation is 1.23456 × 102, where 1.23456 is the
significand, ten is the base, and 2 is the exponent
( b ) 0.0123456 is 1.23456 × 10-2
( c ) - 0.000123456 could be represented as -1.23456 × 10-4
Note that in order to maximize the quantity of representable numbers, floating-point numbers are
typically stored in normalized form. This basically puts the radix point after the first non-zero digit
(i.e. there is single integer to the left of the radix point).
3. IEEE 754 Standard
Single precision floating point is an IEEE 754 standard for encoding binary or decimal floating point
numbers in 4 bytes. The standard has three basic components: the sign bit, the exponent bits, and the
For additional reference, see the following:
1. Textbook – MIPS Assembly Language Programming – Chapter 11, Section 11.6
2. http://en.wikipedia.org/wiki/Single_precision
3. http://babbage.cs.qc.cuny.edu/IEEE-754/
1 of 3
ECE 15B
Spring 2010
mantissa bits to represent real numbers. The representation of a real number in the IEEE-754
standard is computed by first converting the number to normalized binary scientific notation:
(sign) * 2exponent * mantissa
Sign bit (1 bit): 0 denotes a positive number; 1 denotes a negative number.
Exponent bits (8 bits): The exponent field needs to represent both positive and negative
exponents. For IEEE single-precision floats, a ‘bias value’ of 127 is added to do this.
Exponent = Stored value – 127
Mantissa bits (23 bits): For normalized binary notation, the mantissa is of the form
1.xxxxxx, since there is always a single one to left of the binary point (radix point), only the
digits to the left of the radix point are stored, i.e. the significand.
Graphically the IEEE 754 standard is:
And so to compute the decimal value of a stored IEEE 754 floating point number, the following
formula is used:
Real number = -1(sign bit) * 2(Exponent bits -127) * 1.signficand
4. Examples
( 1 ) If the exponent is 0, the stored value is 127 (11111110)
( 2 ) If the exponent is 73, the stored value is 200 (11001000)
( 3 ) If the exponent is -99, the stored value is 28 (0001100)
Note: Exponents of -127 (all 0s in binary notation) and +128 (all 1s) are reserved for special numbers
and is beyond the scope of this project.
5. Project Requirements:
In this project, you are to write function fpcode that takes in a real number is normalized decimal
scientific notation that is already parsed and compute the IEEE 754 representation Your function will
receive as arguments the following:
( a ) $a0: the sign bit
( b ) $a1: the exponent in decimal
( c ) $a2: the mantissa
and so the real number being represented in decimal scientific notation is:
-1$a0 * 10$a1 * $a2
Your code will then convert the given number (in normalized decimal scientific notation) to the
equivalent IEEE 754 standard representation. You are to output the following:
( a ) The 32 bit binary of the IEEE 754 representation
( b ) The hexadecimal value of the IEEE 754 representation
2 of 3
ECE 15B
Spring 2010
( c ) Decimal equivalent (in normalized form or scientific notation)
( 1 ) Normalized form concatenated and output as a string (for example, 1.445 E -12)
will get extra credits.
( 2 ) Note this will not be equivalent to the given number in such cases as transcendental
numbers, repeating decimal numbers, etc (i.e. your conversion will round the
number to fit into the precision of the IEEE 754 standard.
NOTE: You are not allowed to use any floating point macro instruction available in MIPS.
6. Turn-in
Your are to submit a file ‘fpcode.s’ that only includes your function, ‘fpcode’, and a README file
that gives any special instructions for your function or describes any difficulties that were not
overcome in your implementation. Your code must also be well documented; projects with good
code documentation and a detailed README file are more likely to receive partial credit in the case
where your function is not 100% correct.
Email your completed files to: ucsb152010@gmail.com and the subject line should be as follows:
<first name, last name, ECE15B Project 3>,
ex:
Brendon Bolin, ECE 15B, Project 3
3 of 3
Download