您如何在spim中输入命令行参数

发布于 2025-01-26 04:16:47 字数 1024 浏览 3 评论 0原文

我正在尝试使用argcargv在MIPS Simulator Spim中制作程序。 这是我的代码:

.data
nl: .asciiz "\n"

.globl main
.text
main:
  # print argv[0]
  lw $a0, 0($a1)
  li $v0, 4
  syscall
  # print "\n"
  li $v0, 4
  la $a0, nl
  syscall
  # exit
  li $v0, 10
  syscall

当我运行时

$ spim -f args.s
Loaded: /usr/share/spim/exceptions.s                                                                    
args.s

,我将获得正确的结果argv [0](程序的名称)。但是,如果我尝试,

$ spim -f args.s hello
Loaded: /usr/share/spim/exceptions.s
Cannot open file: `(null)'
Memory address out of bounds

我会得到这个错误。我到处搜索,但找不到任何东西。将参数传递到argv []的正确方法是什么? 将代码中的lw更改为lw $ a0,4($ a1)使我获得以下输出。

$ spim -f args.s hello
Loaded: /usr/share/spim/exceptions.s
Cannot open file: `(null)'
SHELL=/bin/zsh

我在虚拟控制台中尝试了,这是一样的。打印所有环境变量之后,更改lw中的偏移量后,它是“从边界出发”的“内存地址”。

我不知道我在做什么错。

I am trying to make programs using argc and argv in MIPS simulator SPIM.
This is my code:

.data
nl: .asciiz "\n"

.globl main
.text
main:
  # print argv[0]
  lw $a0, 0($a1)
  li $v0, 4
  syscall
  # print "\n"
  li $v0, 4
  la $a0, nl
  syscall
  # exit
  li $v0, 10
  syscall

When I run

$ spim -f args.s
Loaded: /usr/share/spim/exceptions.s                                                                    
args.s

I get the correct result argv[0] (the name of the program). But if I try

$ spim -f args.s hello
Loaded: /usr/share/spim/exceptions.s
Cannot open file: `(null)'
Memory address out of bounds

I get that error. I searched everywhere but couldn't find anything. What's the correct way to pass arguments to argv[]?
Changing the lw in the code to lw $a0, 4($a1) gets me the following output.

$ spim -f args.s hello
Loaded: /usr/share/spim/exceptions.s
Cannot open file: `(null)'
SHELL=/bin/zsh

I tried in the virtual console and it's the same. After printing all the environment variables changing the offset in the lw it justs prints "Memory address out of bounds".

I don't know what I am doing wrong.

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

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

发布评论

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

评论(1

酒绊 2025-02-02 04:16:47

最后解决了。使用程序参数的正确方法确实是事实

$ spim -f code.s arg1 arg2 etc

证明,当我说我从AUR安装它时,我使用了官方SourceForge Repo上的最后一个快照将其编译为从Source编辑。
spim.cpp中有一个错误。在第278行之后,它应该说中断;,并且可以完美地工作。我已经在SourceForge中创建了一张票,因此他们可以修补它。

Finally solved it. The right way to use program arguments is indeed

$ spim -f code.s arg1 arg2 etc

Turns out I was wrong when I said that I installed it from the AUR, I compiled it from source using the last snapshot on the official Sourceforge repo.
There is a bug in spim.cpp. After line 278 it should say break; and it works flawlessly. I already created a ticket in Sourceforge so they can patch it.

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