您如何在spim中输入命令行参数
我正在尝试使用argc
和argv
在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后解决了。使用程序参数的正确方法确实是事实
证明,当我说我从AUR安装它时,我使用了官方SourceForge Repo上的最后一个快照将其编译为从Source编辑。
spim.cpp
中有一个错误。在第278行之后,它应该说中断;
,并且可以完美地工作。我已经在SourceForge中创建了一张票,因此他们可以修补它。Finally solved it. The right way to use program arguments is indeed
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 saybreak;
and it works flawlessly. I already created a ticket in Sourceforge so they can patch it.