簡體   English   中英

跳過mips32中的下一條指令

[英]Skipping the next instruction in mips32

假設我要在MIPS中開發一個偽指令,在我將其稱為“ skip $s0后,將跳過下一條指令。

我以為也許可以在$s0上使用$jr ,但是我需要更改$s0的地址。

我該如何解決這個問題?

我想在MIPS中開發一個偽指令,以跳過下一條指令

比較簡單的方法是使用始終經過驗證的“分支”。

beqc $0,$0,2

如果$ 0 == $ 0(即始終),將用PC PC+(2*4)替換PC並跳過下一條指令。

這是經常用於處理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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM