'How do you enter command line arguments in SPIM
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.
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Santiago Trini |