How to set a floating point register to 0 in MIPS (or clear its value).

时光毁灭记忆、已成空白 提交于 2019-12-25 06:38:57

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/22770778/how-to-set-a-floating-point-register-to-0-in-mips-or-clear-its-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!