Question

I'm currently implementing a square matrix multiplier containing single floating point numbers in MIPS assembly line code.

My problem is that once I am done summing the multiplications of the corresponding rows and columns in order to calculate my dot product I want to clear that floating point register so I can calculate the dot product for the next entry in the product matrix.Right now I keep adding the current dot product with all the previous dot products.

Things I've tried to set the floating point register as zero:

l.s $f3,$0 #loading zero into the register

addi $t0,$t0,$zero #setting a temp register as zero
l.s $f3,($t0)

I keep getting an error indicating a runtime exception and an address out of range.

Was it helpful?

Solution

What you are doing is loading a float from address 0, hence the fault. You want to load the value 0 instead. You can do that by mtc1 $zero, $f3. This works because all zero bits mean zero in floating point too. For other values, you'd have to do a cvt.s.w afterwards to convert the integer to floating point. Alternatively you can subtract the register from itself by sub.s $f3, $f3, $f3. Don't know if this works for all possible values (I am thinking of NaN, Inf and such) or if it is faster than transferring from the integer zero register.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top