增加分支地址上的程序计数器

时间:2014-02-01 02:25:48

标签: architecture mips cpu-architecture

如何使用MIPS指令递增程序计数器?我有以下代码:

if (R[rs] > 0)
    R[rs] = R[rs] - 1
else
    PC = PC + 4 - Branch Address

到目前为止,我认为这有效:

 slt $t0, $rs, $rt #This is a pseudoinstruction translation for R[rs] > 0
 bne $t0, $zero, ELSE 
 add $rs, $rs, -1 #add -1 to $rs to decrement
Else:
                  #do something here: Maybe jump to branch address? jr branch address How to get branch address?

1 个答案:

答案 0 :(得分:0)

 slt $t0, $rs, $rt #This is a pseudoinstruction translation for R[rs] > 0
 bne $t0, $zero, Else 
 add $rs, $rs, -1 #add -1 to $rs to decrement
 b endif
Else:
 # do the else
endif: 
 # rest of the program