Reputation: 1
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.
Upvotes: 0
Views: 193
Reputation: 26666
I don't know why the result is infinity.
The value in $f4
is 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 $f5
is 0x41160000, which is 9.375.
The program then multiplies these two values together using
mul.s $f8, $f4, $f5
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 $f10
is generated by adding $f9
to $f8
,
add.s $f10, $f9, $f8
This propagates the infinity/overflow from $f8
into $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
Upvotes: 1