使用浮点指令得到十进制结果 [英] Use the floating point instructions to get results in decimal
问题描述
你好,我编码MIPS一个小程序,9之间分配2并显示result.This是code
Hi I'm coding a small program in MIPS that divide 2 between 9 and show the result.This is the code
li $t1, 2
li $t2, 9
li $v0, 2
div $t0,$t2,$t1
move $a0,$t0
syscall
(这不是完整的code,只是部分搬运师)
(this is not the full code, just the section handling division)
因此,2/9为0.2222222222222222
So, 2 / 9 is 0.2222222222222222
但是当我运行它,我只能得到0.0
But when I run it I only get 0.0
我如何展现真实的结果(0.2222222222222222)?
How I show the true result (0.2222222222222222)?
我一直在说,我使用的是整数,而不是浮点,我必须使用浮点指令得到十进制的结果。我应该查查div.x指令,但div.x没有一个公认的运营商。
I've been said that I'm using integer instead of floating point, that I must use the floating point instructions to get results in decimal. That I should look up the div.x instruction, but div.x is not a recognized operator.
所以,我pretty很多空白。我不明白该怎么做。
So, I'm pretty much in blank. I don't understand what to do.
可能有人张贴code,显示浮点结果?
Could someone post the code to show the floating point result?
先谢谢了。
推荐答案
好吧,经过长时间的尝试和错误打印真正的结果正确的方法是:
Ok, after a long try and mistake the right way to print the true result is:
设置2浮动点(在正确的方向感谢Paul R代表点我),使用伪li.s寄存器
Set 2 floating points registers using pseudo li.s (Thanks to Paul R for point me in the right direction)
li.s $f1, 2.0
li.s $f2, 9.0
显然,prepare打印浮动
Obviously, prepare to print a float
li $v0, 2
目前分裂,而不是 DIV $ T0,T2 $,$ T1
我应该使用
At division instead of div $t0,$t2,$t1
I should use
div.s $f12,$f1,$f2
和代替动$ A0,$ T0
我应该只是
syscall
有没有必要动,DIV.S打印出局,结果一下子所以没有真正需要的$ F12的内容移动到$ A0打印其内容。
There is no need to move, div.s prints outs the result at once so there is no real need to move the contents of $f12 into $a0 for print its content.
这是一个真正的耻辱,火星并不implment伪li.s.我不得不尝试这对PCSPIM ...
It's a real shame that mars doesn't implment the pseudo li.s. I had to try this on PCSPIM...
最后code是
.globl main
.text
main:
li.s $f1, 2.0
li.s $f2, 9.0
li $v0, 2
div.s $f12,$f1,$f2
syscall
li $v0, 10
syscall
当你运行它,你会得到0.22222222,2分9之间的真实结果。
When you run it you'll get 0.22222222, the true result of dividing 2 between 9.
这篇关于使用浮点指令得到十进制结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!