mips延迟槽bnez和bnezl的区别

由于mips的指令采用流水线的形式。取指 译码 执行 内存操作 回写

因此在位于跳转和分支情况下。执行分支跳转时,下一条指令已经被执行。

80031DB8  bnez    $v0, loc_80031F58
80031DBC  move    $v0, $zero
例如如上的指令。

BNEZ是branch not equal to zero

当BNEZ进入执行阶段还没有执行时,move进入译码还没有执行的阶段

当BNEZ执行完毕后(此时的V0是之前的V0)。move译码完毕,接下来一定能够执行。

因此不管BNEZ跳不跳转。V0都将会被修改为0


这是bnez.

而BNEZL是 branch not equal to zero likely 这个likely文章大了。likely表示可能性高。unlikely表示可能性低。

对于BNEZL则不是这样。

80031DB8  bnezl    $v0, loc_80031F58
80031DBC  move    $v0, $zero
bnezl表示必须要跳转成立。下面一条延迟槽才会被执行。

如果之前v0不是0。那么就会跳转到 1F58这里。此时由于跳转成立。那么move v0,0会被执行。

如果v0是0,那么不会跳转到1F58.跳转不成立。那么move v0,0不会被执行。


如果在branch likely的延迟槽里面下断点。那么只有在条件成立的时候才会断下来。


参看解释

https://www.math.ku.edu/computing/cluster/totalview.6.0.0-0-doc/ref_guide/architectures29.html


MIPS Delay Slot Instructions

On the MIPS architecture, jump and branch instructions have a "delay slot". This means that the instruction after the jump or branch instruction is executed before the jump or branch is executed.

In addition, there is a group of "branch likely" conditional branch instructions in which the instruction in the delay slot is executed only if the branch is taken.

The MIPS processors execute the jump or branch instruction and the delay slot instruction as an indivisible unit. If an exception occurs as a result of executing the delay slot instruction, the branch or jump instruction is not executed, and the exception appears to have been caused by the jump or branch instruction.

This behavior of the MIPS processors affects both the TotalView instruction step command and TotalView breakpoints.

The TotalView instruction step command will step both the jump or branch instruction and the delay slot instruction as if they were a single instruction.

If a breakpoint is placed on a delay slot instruction, execution will stop at the jump or branch preceding the delay slot instruction, and TotalView will not know that it is at a breakpoint. At this point, attempting to continue the thread that hit the breakpoint without first removing the breakpoint will cause the thread to hit the breakpoint again without executing any instructions. Before continuing the thread, you must remove the breakpoint. If you need to reestablish the breakpoint, you might then use the instruction step command to execute just the delay slot instruction and the branch.

A breakpoint placed on a delay slot instruction of a branch likely instruction will be hit only if the branch is going to be taken.







你可能感兴趣的:(arm,mips等学习)