mips延迟槽bnez和bnezl的区别

本文详细解析了MIPS架构中BNEZ和BNEZL分支指令的工作原理及延迟槽机制,阐述了这些指令如何影响后续指令的执行,并讨论了在使用TotalView调试工具时遇到的相关行为。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由于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.







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值