1

我在让我编译的汇编文件在 SPIM 上工作时遇到了很多麻烦。基本上我想写一个 c++ 文件,然后生成一个 .s 文件,我可以在 SPIM 中打开而不会出错。这意味着程序集必须使用 MIPS I 指令(某些 MIPS II)在 MIPS32 ABI 中。我该怎么做呢?现在我正在使用 g++,但是当我尝试在 SPIM 中运行文件时遇到了重大错误。我正在使用 MAC OSx 10.6.3,并且正在 Linux 机器上进行远程编译。有没有我可以使用的特殊编译器让这对我来说很容易?

4

1 回答 1

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.

于 2010-07-12T20:06:34.970 回答