I’m having a lot of trouble getting my compiled assembly file working on SPIM. Basically I want to write a c++ file, and then generate a .s file that I can open in SPIM without error. This means that the assembly must be in MIPS32 ABI using MIPS I instructions (some MIPS II). How do I do this? Right now I’m using g++ but I’m having major errors when I try ot run the file in SPIM. I’m working on MAC OSx 10.6.3 and I’m compiling remotely on a linux machine. Is there a special compiler I can use that will make this easy for me?
Share
Give the compiler -S option, it will generate the assembly code. Then you will have to edit the code so that SPIM accepts it.
You’ll also want
g++ -S -fno-delayed-branchif you enable optimization like-O1or-Ogfor more readable code. Usually SPIM is configured to simulate a MIPS without branch-delay slots, but gcc will assume that the instruction after a branch is run even if it’s taken.-fno-delayed-branchgets gcc to fill any branch-delay slots withnop.Another useful option is
-fverbose-asmto have gcc add comments with the C variable name of each operand.You’ll want to avoid using C++ libraries like
std::vectorthat compile to a lot of extra code vs. local arrays, especially without optimization, unless you really need those features.