2015-10-20 198 views
0

我正在研究一个mips程序的while循环,该程序可以产生中奖彩票的几率。这是我到目前为止。你能否建议你是否认为这会起作用?以59个镐和3个球为例。MIPS while循环

Load 59 into $t0 
Load 3 into $t1 
Load 1 into $t2 
Load 1 into $t3 

Loop: while $t1 > 0 
Divide $t2 by $t0 and put in $t4 
Multiply $t4 by $t3 and put in $t3 
Subtract $t1 by 1 #subtracts balls by 1 
Subtract $t0 by 1 #subtracts max picks by 
**repeat loop** 

有人可能会建议,如果这是可能的mips,因为我只是在我的第一个程序工作,只有Java背景。

回答

1

是的,这是可能的,但你必须把它放在浮点寄存器$ F0 ... $ F31:

li $t0 , 59 // values assignment to temporary registers 
    li $t1 , 3 

    mtc1 $t0,$f0 //move from int register to float-point register 
    cvt.s.w $f0,$f0 //Convert int values to float-point values 

    mtc1 $t1,$f1 
    cvt.s.w $f1,$f1 //Convert int values to float-point values 

    li $t2 , 1 
    li $t3 , 1 

    mtc1 $t2, $f2 
    cvt.s.w $f2,$f2 

    mtc1 $t3, $f3 
    cvt.s.w $f3,$f3 

    li $t6 , 1 
    mtc1 $t6, $f6 
    cvt.s.w $f6,$f6 

    //Start of the while loop 

    li $t5, 0 
    mtc1 $t5, $f5 
    cvt.s.w $f5,$f5 

    while : c.gt.s $f1, $f5 
    bc1f endwhile 
    //checks the intital condition and if it's false jump to endwhile 
    div.s $f4,$f2,$f0 // $f4 = $f2/$f0 
    mult.s $f3, $f3 ,$f4 // $f3 = $f3 * $f4 

    sub.s $f0, $f0, $f6 
    sub.s $f1, $f1, $f6 

    b while //jump to label while 
    endwhile: // your code 

如果您有任何麻烦,也许你可以检查该网页,认为这是一个很好的参考:http://logos.cs.uic.edu/366/notes/mips%20quick%20tutorial.htm http://www.cim.mcgill.ca/~langer/273/12-coprocessors.pdf

+0

Xavier,任何机会,你可以看看唉我的计划我放在一起,我无法得到输出的工作。感谢您的帮助。 http://stackoverflow.com/questions/33249638/mips-input-and-output-help-floating-point – Cfs0004