转换 C++ SPIM 的汇编代码

发布于 2024-09-07 02:53:20 字数 253 浏览 2 评论 0原文

我在让已编译的程序集文件在 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的笑 2024-09-14 02:53:20

给编译器-S选项,它将生成汇编代码。然后您必须编辑代码以便 SPIM 接受它。

如果您启用 -O1-Og 等优化以获得更具可读性的代码,您还需要 g++ -S -fno-delayed-branch 。通常 SPIM 配置为模拟没有分支延迟槽的 MIPS,但 gcc 会假定分支后的指令即使被采用,也会运行。 -fno-delayed-branch 让 gcc 用 nop 填充任何分支延迟槽。

另一个有用的选项是 -fverbose-asm ,让 gcc 添加带有每个操作数的 C 变量名称的注释。

您需要避免使用像 std::vector 这样的 C++ 库,这些库与本地数组相比会编译成大量额外代码,尤其是在没有优化的情况下,除非您确实需要这些功能。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文