MIPS while循环

时间:2015-10-20 21:49:25

标签: math mips mips32 mips64

我正在为mips程序进行一个while循环,它可以产生赢得彩票的几率。这是我到目前为止所拥有的。如果您认为这样可行,您能告诉我吗?使用59个选中3个球的例子。

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 个答案:

答案 0 :(得分: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

相关问题