Reputation: 57
This is part of a program I have been working on and having trouble writing this lookup function part of the code. Here is the code in C but am having trouble converting it to MIPS. Any help would be appreciated.
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
Upvotes: 0
Views: 2326
Reputation: 882626
Get yourself a compiler capable of generating MIPS output, such as gcc
and then compile your code with the option "produce assembly output". gcc -S
can do this for you.
Then take that code and examine/use it. If you want to understand it, you may want to ensure that optimisation is at a low level (such as with -O0
). Otherwise there's a good chance you won't be able to make any sense of what the compiler generates.
Upvotes: 3