Write a program to perform the multiplication of two single-precision IEEE 754 standard floating-point numbers without using MIPS floating-point arithmetic instructions. The input data is read from a file stored in binary format on the disk named FLOAT2.BIN (2 values x 4 bytes = 8 bytes).
.data
num1: .float 2.5
num2: .float 3.75
.text
.globl main
main:
lwc1 $f0, num1
lwc1 $f1, num2
li $t0, 0x80000000
mtc1 $t0, $f2
lui $t0, 0x3f80
mtc1 $t0, $f3
sll $t0, $t0, 1
mtc1 $t0, $f4
mul.s $f5, $f0, $f1
mul.s $f6, $f2, $f5
mul.s $f7, $f3, $f5
mul.s $f8, $f4, $f5
add.s $f9, $f6, $f7
add.s $f10, $f9, $f8
mov.s $f12, $f10
li $v0, 2
mov.s $f12, $f10
syscall
li $v0, 10
syscall
I don't know why the result is infinity.
The value in
$f4is 0x7f000000, which is 1.7014118346e+38, notably, a very large number, whose exponent is at the limit of single precision floating point.The value in
$f5is 0x41160000, which is 9.375.The program then multiplies these two values together using
Numerically the result is 1.5950735949375e+39, however, this value overflows the single precision floating point format, so is converted to "infinity", which is stored in
$f8.Later
$f10is generated by adding$f9to$f8,This propagates the infinity/overflow from
$f8into$f10, and that's what is being printed.You can observe those values in the floating point registers using a good floating point calculator like: https://www.h-schmidt.net/FloatConverter/IEEE754.html