Convert Integer to Double in MIPS

后端 未结 1 343
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-05 13:55

I want to divide two values that are in $tn registers.

I have to divide these two values to get a double result but the function div only r

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-05 14:37

    You have to move and convert the integer stored in a general purpose register to floating point or double register.

    Assuming your number is stored in $a1, To convert to a double pair ($f12, $f13) you have to issue:

      mtc1.d $a1, $f12
      cvt.d.w $f12, $f12
    

    And to convert it to a single precision float ($f12) you'd do:

      mtc1 $a1, $f12
      cvt.s.w $f12, $f12
    

    Then you can use div.d or div.s to do floating-point division and get a floating point result.

    0 讨论(0)
提交回复
热议问题