假设我想在 MIPS 中开发一个伪指令,在我调用此跳过指令 say 后跳过下一条指令skip $s0
。
我想也许我可以使用$jr
on $s0
,但我需要更改$s0
.
我该如何解决这个问题?
我想在 MIPS 中开发一个跳过下一条指令的伪指令
更简单的方法是使用始终经过验证的“分支”。
beqc $0,$0,2
将替换PC
为PC+(2*4)
if $0==$0 (即始终)并跳过下一条指令。
这是一个经常用来处理 if-then-else 的技巧
if(a1)
a2=3;
else
a3=4;
beqc $a1, $0, else
addi $a2, $0, 3
beqc $0, $0, 2 ; go to end of if then else
else: addi $a3, $0, 4
# end of if-then else
beqc
是 mips64-v6 中引入的无延迟分支(以及许多其他具有零延迟槽的分支/跳转)。
使用旧版本的 mips ISA,不可能跳过下一条指令,因为所有分支都执行以下指令。跳过第二条指令,思路是一样的。
beq $0,$0,2 ; delayed branch. execute next instruction and if test
; is true (ie always) go to pc+4+2*4
add $0, $0, $0 ; aka nop (because of the delay slot)
xxx $a1, $a2, $a3 ; this instruction will be skipped
yyy $t1, $t2, $t3 ; and this instruction will be executed
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句