Reputation: 155
Suppose that I want to output the same string I inserted , I would use the following
main:
la $a0,buffer #allocate space for $a0
li $v0,8 #read the string input
syscall
li $v0, 4 #print the string input
syscall
li $v0,10 #stop the program
syscall
Well, that wont work and I have to add
li $a1,..
and I don't know why ?
Upvotes: 0
Views: 38
Reputation: 4961
See the MARS/spim syscall doc here.
For syscall 8 you need to specify a buffer address in $a0
and a length in $a1
. My guess is the code above doesn't work because the program starts off with $a1
preset to zero meaning that you will read in 0 bytes.
In addition, your comment on the first line is wrong. Using la
does not allocate space. This should be done in the text
segment where I assume the buffer
label is defined. Using la
only loads the address of the label buffer
into a register.
Upvotes: 1