1

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?

Dan Snyder
  • 1,483
  • 7
  • 20
  • 29
  • Sorry, I'm not familiar with that term really. I'm compiling using "mipseb-linux-g++". I'm doing it on a linux machine, MIPS 3k. – Dan Snyder Jun 23 '10 at 16:38

1 Answers1

2

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-branch if you enable optimization like -O1 or -Og for 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-branch gets gcc to fill any branch-delay slots with nop.

Another useful option is -fverbose-asm to have gcc add comments with the C variable name of each operand.

You'll want to avoid using C++ libraries like std::vector that compile to a lot of extra code vs. local arrays, especially without optimization, unless you really need those features.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
zvrba
  • 24,186
  • 3
  • 55
  • 65
  • By the way, C++ requires a considerable run-time support from other libraries. Try that first with an ordinary C program. – zvrba Jul 12 '10 at 20:07