2011-07-24 20 views
1

我剛剛開始使用SPIM模擬器進行MIPS。有人可以幫我轉換這種說法嗎?在MIPS中表達此聲明

if(as>47 && as<58) function(); 
else continue; 

Thanx提前。 :)

回答

5

我的MIPS有點生疏,所以如果沒有小的調整就無法正常工作,請提前道歉,但是這應該有希望給你一個你想做什麼的好主意。

(如果你發現這行不通,請讓我知道這樣我就可以對帖子進行編輯)

# Assume 'as' is in $s0 
li $t2, 1   # $t2 = 1 
slti $t0, $s0, 58 # $t0 = $s0 < 58 
addi $t1, $s0, 1 # $t1 = $s0 + 1 
slti $t1, 47, $s0 # $t1 = 47 < $s0 + 1 (sgti does not exist) 
and $t0, $t0, $t1 # $t0 = $t0 && $t1 

bne $t0, $t2, cont  # if ($t0 != $t2) goto cont 

function: # Label is optional. 
# If both conditions are true, the bne won't branch, so we will 
# fall through to function: and run whatever code it has. 
# otherwise, we jump to cont: and all the func code is skipped. 
    # ... 

cont: # continue; 

    # ... 

注意到,現在,函數()實際上不是一個函數。你可以然而jal function,並有該塊駐留在別的地方。這是一個good reference of the MIPS instruction set

MIPS中的訣竅是由於您沒有比指令大的指令,所以必須使用相反的指令。

請記住,>的反義詞不是<,它是< =。

+1

+1看起來很適合我。 IIRC的條件可以簡化爲'addi $ t0,$ s0,-48; sltiu $ t0,$ t0,58 - 48'在這種情況下。 – user786653

+0

Thanx男人!!!!!!! :D:D –