2011-11-02 191 views
1

這是我一直在編寫的程序的一部分,無法編寫此代碼的查找函數部分。這裏是C語言的代碼,但是很難將其轉換爲MIPS。任何幫助,將不勝感激。將C代碼轉換爲MIPS彙編

Pseudo codes: 
    $a0 = 0  # index into symTab array 
compare: 
    if ($a0 >= symAV($0)) 
    goto not_found 
    if (TOKEN[0] <> symTab[$a0]) 
    goto nextSym 
if (TOKEN[1] <> symTab+4[$a0]) 
    goto nextSym 
    return  # found the symbol 
nextSym: 
$t0++  # should be incremented by 16 in MIPS 
goto compare 

not_found: 
$a0 = -1 
return 
+0

哪個部位有問題?到目前爲止你做了什麼? –

+2

您是否在尋找MIPS的C編譯器? –

+0

我是MIPS編程新手,仍然不知道所有的寄存器等。我只是不知道如何逐行寫入並將其寫入MIPS。 – ellio20

回答

3

讓自己能夠產生MIPS輸出,如gcc,然後用選項「生成彙編輸出」編譯代碼的編譯器。 gcc -S可以爲你做這個。

然後拿這個代碼,並檢查/使用它。如果你想理解它,你可能想要確保優化是在一個較低的水平(例如與-O0)。否則,您很可能無法理解編譯器生成的內容。