无效的程序计数器值:0

发布于 2024-09-01 09:36:50 字数 233 浏览 4 评论 0原文

我目前正在 MIPS 处理器下使用汇编语言。我目前在 使用 MARS 模拟器,由于未知的原因,我每次运行后都会收到以下错误消息:

Go:运行 try.s

错误:无效的程序计数器值:0

Go:执行因错误而终止。

我收到此错误消息,与我正在使用的代码无关,只是想知道这是否是一个错误 在火星模拟器中或者如果我缺少什么。

I'm currently working with assembly language under the MIPS processor. I'm currently
using MARS simulator and for reasons unknown I get the following error message after every run:

Go: running try.s

Error in : invalid program counter value: 0

Go: execution terminated with errors.

I get this error message independent of the code I'm using, just wondering if this is a bug
in the MARS simulator or if it's something I'm missing.

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

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

发布评论

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

评论(3

阳光下慵懒的猫 2024-09-08 09:36:50

您可能会使用jr $ra(返回调用者)来完成您的程序。然而,MARS 执行的代码没有调用者 - 它在启动时执行并且没有可返回的函数,因此 $ra 的内容为零。

在 MARS 上结束程序的正确方法是使用“exit”系统调用:

    li $v0, 10
    syscall

You probably finish your program with a jr $ra (return to caller). However, the code executed by MARS doesn't have a caller - it's executed at startup and has no function to return to, so the contents of $ra are zero.

The correct way to end a program on MARS is using the "exit" syscall:

    li $v0, 10
    syscall
轻许诺言 2024-09-08 09:36:50

我是 MIPS 新手,刚刚遇到了这个问题。
这就是我所拥有的:

    .data

    .text

swap:
    # do stuff
    jr  $ra

main:
    # do stuff
    jal swap
    li  $v0,10
    syscall

我通过将其更改为以下内容来修复它:

    .data

    .text
main:
    # do stuff
    jal swap
    li  $v0,10
    syscall

swap:
    # do stuff
    jr  $ra

注意我将 main 移至交换之前。我错误地认为 main 是一个保留标签。并且它会首先自动直接跳到主程序。但显然情况并非如此,因为在我在 main 中调用 jal swap 之前它已经命中了我的 jr $ra 指令。

无论如何,我希望这会有所帮助。

I am new to MIPS and I just had this problem.
This is what I had:

    .data

    .text

swap:
    # do stuff
    jr  $ra

main:
    # do stuff
    jal swap
    li  $v0,10
    syscall

I fixed it by changing it to this:

    .data

    .text
main:
    # do stuff
    jal swap
    li  $v0,10
    syscall

swap:
    # do stuff
    jr  $ra

Notice I moved main to be before swap. I mistakenly assumed that main was a reserved label. And that it would automatically jump straight to main first. But apparently that isn't the case because it was hitting my jr $ra instruction before I got to call jal swap in main.

Anyway, I hope this helps.

红颜悴 2024-09-08 09:36:50

我知道这个问题已经很老了,但是对于像我一样拼命在谷歌上搜索答案的人来说:尝试执行上述系统调用而不是返回,并尝试将主函数放在所有其他标签之前。此外,“设置”菜单下还有一个“将程序计数器初始化为全局“主”(如果已定义)”;确保已选中。我不知道启用该功能是否允许您将主标签放在其他标签之后,因为我还没有尝试过。我所描述的是我为使其发挥作用所做的事情,除此之外没有其他任何内容。祝你好运!

I know this question is old, but for anyone who was just like me and was desperately Googling for an answer: try doing the above syscall thing instead of a return, and try putting your main function before all other labels. Also, there's a "Initialize Program Counter to global "main" if defined" under the Settings menu; make sure that is checked. I do not know if enabling that allows you to put your main label after other labels, as I haven't tried that yet. What I have described is what I did to make it work, and nothing else. Good luck!

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