LAB 2: Floating Point Conversion
(Due midnite Mon 3/2/98)
PART I:
Write a SAL program that accepts a floating point number as input and then
prints out its mantissa and exponent values in IEEE floating point format.
- INPUT: A floating point number in base 10 written in decimal format
(Eg. 102.125)
- OUTPUT:
- The exponent is printed as base 10 equivalent of the IEEE
excess-127 exponent
- The mantissa is printed as base 2 normalized
(i.e., 1.0 <= mantissa < 2.0)
A sample execution of such a program is shown below:
> Enter a floating point number (base 10): 102.125
> Exponent: 133, Mantissa: 1.10011000100000000000000
(102.125 = 1100110.001 = 1.100110001 * 2^6
=> Exponent=6+127=133, Mantissa=1.10011000100000000000000)
PART II:
Now, convert the above SAL program to MAL code. You DO NOT necessarily have to
use procedures.
To implement MAL code for reading in a floating point number
from the input, take a look at the MAL code on pages 245-249 of the text
for clues. Here, you will also find a procedure to print out an integer number
to the output.
Note:
- You do not necessarily have to submit both SAL and MAL programs.
You MUST submit the MAL code. However, by also submitting the SAL code,
you will be able to get partial points if your MAL code does NOT work
but your SAL code does.
- Moving a float type to a word type will preserve the bits
from the float type. That is, it is equivalent to a bit copy from a
type of .float to a type of .word.
This means that if you try to print the new type as a .word,
you will get random garbage. So, this will NOT work!