For this assignment, we will decode the different parts of a floating point number. Each number input by the user will be written out in two ways:
Since the SPIM simulator only outputs numeric values in decimal, you will need to output the hex and binary values as a character string.
Your program should prompt the user for a floating point number. This number should be read in as a SINGLE PRECISION floating point number. Your program should then output the number in the two specified ways. Then your program is to prompt the user if they wish to repeat the operation with another floating point number. The user is to answer with either a y for yes or an n for n. An answer other than y or n should be treated as an n for no. If the answer is no, quit the program. If the answer is yes, loop back to the top and re-run the program.
A single precision floating point number is stored in a sign and magnitude format in 32 bits. The magnitude has two parts: the fractional part of the mantissa and the exponent.
Let us look at the single precision floating point representation for 0.625.
0.625 = 0.5 + 0.125 = 1/2 + 1/8 = 0.101 (in binary) = 1.01 * 2-1 (normalized) sign: positive mantissa: 1.01 (in binary) exponent: -1 (in decimal) encoded sign value: 0 encoded mantissa value: 1.01 01 (fractional part only) 01000000000000000000000 (extending to 23 bits) encoded exponent value: -1 + 127 = 126 (in excess-127) = 01111110 (in binary) Entire encoded value: 001111110010000000000000000000000 Translation: seeeeeeeeffffffffffffffffffffffff where: s indicates the sign bit e indicates the exponent f indicates the fractional part of the mantissaThe output given by your program for the value of 0.625 could be as follows. The non-bold information can be given in any readable format, while the bold information should be output as shown.
For the floating point value of 0.625 The encoded value in hex is: 3f200000 Which is +1.01000000000000000000000 * 2^-1The creation of the hex value has nothing to do with the value being in sigle precision floating point format. The same algorithm could be used for displaying any value from a register in hex.
The programs will be graded based on how they execute on xspim running in the CS Department computers. You are to submit your program electronically using the the turnin command with the project name of mp2. Your program must be well commented, use blank lines to separate logical sections of your code and align labels, opcodes, operand and comments in neat columns.
Register Name | Alternative Name | Description |
---|---|---|
$0 | the value 0 | |
$1 | $at | reserved by the assembler |
$2 - $3 | $v0 - $v1 | expression evaluation and function results |
$4 - $7 | $a0 - $a3 | the first four parameters - not preserved across procedure calls |
$8 - $15 | $t0 - $t7 | temporaries - not preserved across procedure calls |
$16 - $23 | $s0 - $s7 | saved values - preserved across procedure calls |
$24 - $25 | $t8 - $t9 | temporaries - not preserved across procedure calls |
$26 - $27 | $k0 - $k | reserved for use by the operating system |
$28 | $gp | global pointer |
$29 | $sp | stack pointer |
$30 | $s8 | saved value - preserved across procedure calls |
$31 | $ra | return address |
$f0 - $f2 | floating point function results | |
$f4 - $f10 | temporaries - not preserved across procedure calls | |
$f12 - $f14 | the first two floating point parameters - not preserved across procedure calls | |
$f16 - $18 | temporaries - not preserved across procedure calls | |
$f20 - $f30 | saved values - preserved across procedure calls |
Service | System Call Code placed in $2/$v0 | Arguments | Results |
---|---|---|---|
print_int | 1 | $a0 = integer | |
print_float | 2 | $f12 = float | |
print_double | 3 | $f12 = double | |
print_string | 4 | $a0 = address of string | |
read_int | 5 | integer (in $v0) | |
read_float | 6 | float (in $f0) | |
read_double | 7 | double (in $f0) | |
read_string | 8 | $a0 = address of string buffer $a1 = length of string buffer | |
sbrk | 9 | $a0 = amount | address (in $v0) |
exit | 10 |
The following special characters are used with character strings in SPIM. The special characters follow the C language convention:
Character | Encoding Sequence |
---|---|
Newline | \n |
Tab | \t |
Double quote | \" |