Department of Electrical Engineering and Computer Science
EECS
61C, Summer 2004
Lab 3-2: Integer and Floating Point Representation
To examine how computers store integer and floating point values.
P&H, 4.2, 4.3, 4.9
Recall that the single
precision floating point number is stored as:
SEEE
EEEE EIII IIII IIII IIII IIII IIII
S is the sign bit, 0 for positive, 1 for negative
E is the exponent, bias 127
I is the significant, with an implicit 1
For example, the floating point representation of 1.0 would be 0x3F800000.
Verify to yourself that this is correct.
Exercise
1: Integer Numbers
(P&H Ex. 4.17) Find the shortest sequence of MIPS
instructions to determine if there is a carry out from the addition of two
registers, say $t3 and $t4. Place a 0 or 1 in register $t2 if the carry out is
0 or 1, respectively (this can be done in just two instructions). Verify that
your code works for the following values:
Operand |
Operand |
Carry out? |
|
|
no |
|
|
no |
|
|
yes |
Exercise
2: Floating Point Numbers
Find a positive floating point value x, for which x+1.0=x. Verify your result in
a MIPS assembly language program, and determine the stored exponent and
fraction for your x value (either on the computer or on paper).
We have provided a MIPS program
~cs61c/labs/lab3-2/lab3-2.s that allows you to experiment with adding floating point
values. It leaves the output in $f12 and also $s0, so you can examine the hex
representation of the floating point value by printing out $s0.
Exercise
3: Floating Point Numbers Revisited
Next, find the smallest positive floating point value x for which x+1.0=x. Again, determine the stored
exponent and fraction for x.
Exercise
4: Floating Point Associativity
Finally, using what you have learned from the last two parts, determine a set
of positive floating point numbers such that adding these numbers in a
different order can yield a different value. You can do this
using only three numbers. (Hint: Experiment with adding up different amounts of
the x value you determined in part 3, and the value 1.0).
This shows that for three floating point numbers a
, b
,
and c
:
a+b+c
does not
necessarily equal c+b+a
.