I’m a newbie with MIPS & MARS. As a part of my program, I want to read a string from the user.
I have a simple code as follows
.globl test
.data 0x10010000
foo: .asciiz "Input a string"
.data 0x10020000
in: .asciiz "xyz"
.text 0x00400000
test:
li $v0, 54
add $a0, $zero, 0x1001
add $a1, $zero, 0x1002
add $a2, $zero, 3
syscall
The idea is to read a string of say length at most 3 into memory at 0x1002. Running the code gives me “Runtime exception at 0x00400010: address out of range 0x00001001”.
Why does this happen? How do I fix it? I suspect I’m doing something very silly, but cannot figure it out.
I think you’re mixed up with addressing. You’ve defined your buffer space at 0x10020000 but you’re using an address of 0x1002 for the syscall. Same thing with the dialog string.
Your
$a0should be the address of the string that gets shown in the dialog; I suspect this should befoo:And your buffer should be
in:Edit: these are replacements for the
adds, so in the end it should look like:I’ve also replaced the
$a2line with something simpler. Try to see how they’re equivalent.