问题描述
在SPIM上运行已编译的程序集文件时遇到很多麻烦.基本上,我想编写一个c ++文件,然后生成一个.s文件,可以在SPIM中打开它而不会出现错误.这意味着程序集必须使用MIPS I指令(某些MIPS II)在MIPS32 ABI中.我该怎么做呢?现在,我正在使用g ++,但是尝试在SPIM中运行该文件时出现严重错误.我正在使用MAC OSx 10.6.3,并且正在Linux机器上进行远程编译.我可以使用一个特殊的编译器来简化此工作吗?
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?
推荐答案
赋予编译器-S选项,它将生成汇编代码.然后,您将必须编辑代码,以便SPIM接受它.
Give the compiler -S option, it will generate the assembly code. Then you will have to edit the code so that SPIM accepts it.
如果您启用诸如 -O1
或 -Og
之类的优化功能,则还需要 g ++ -S -fno-delayed-branch
可读的代码.通常将SPIM配置为模拟不具有分支延迟插槽的MIPS,但是gcc会假定分支执行后的指令即使已被执行. -fno-delayed-branch
获取gcc,以使用 nop
填充所有分支延迟插槽.
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
.
另一个有用的选项是 -fverbose-asm
,让gcc使用每个操作数的C变量名称添加注释.
Another useful option is -fverbose-asm
to have gcc add comments with the C variable name of each operand.
您将要避免使用像 std :: vector
这样的C ++库,这些库可以编译成很多额外的代码,而不是本地数组,尤其是没有优化的情况,除非您确实需要这些功能.
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.
这篇关于将C ++代码转换为SPIM的程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!