remu指令扩展为包括break指令-始终停止程序

时间:2018-11-08 14:32:46

标签: mips qtspim

我正在使用QtSpim学习MIPS。在下面的代码中,remu伪指令被扩展为包括break指令。我认为中断是为了除以零,但是在这种情况下,无论如何,它将使代码无法运行:

            .text
            .globl main

main:       li          $s0, 113        # $s0 holds n, the number to test.
            div         $s1, $s0, 2     # $s1 is n / 2, the limit for the loop.
            li          $s2, 2          # $s2 is the counter starting at 2.

while:      beq         $s2, $s1, set
            nop
            remu        $s3, $s0, $s2
            beq         $s3, $0, unset
            nop
            addiu       $s2, $s2, 1
            j           while
            nop

unset:      li          $s7, 0          # $s7 is unset if n isn't prime.
            j           end
            nop

set:        li          $s7, 1          # $s7 is set because n is prime.

end:

remu指令扩展为:

[00400040] 16400001  bne $18, $0, 4           ; 10: remu $s3, $s0, $s2 
[00400044] 0000000d  break                    
[00400048] 0212001b  divu $16, $18            
[0040004c] 00009810  mfhi $19

即使$ 18($ s2)非零,break指令也总是停止代码。

0 个答案:

没有答案