sprockston
asked on
Easy question? Storing a register in MIPS to a predefined "asciiz" word.
In my data section of my assembly file, I have the following defined:
word: .asciiz "test\n"
Later, in my code, I have the register $t3 set to the word "example".
ie:
move $a0, $t3
li $v0, 4
syscall
Prints "example".
How to I move the contents of $t3 into 'word' so that
la $a0, word
li $v0, 4
syscall
Prints "example"
Or, storing it so $s1 has the address of the 'example', such that
la $s1, word
would accomplish.
Thanks in advance! :)
word: .asciiz "test\n"
Later, in my code, I have the register $t3 set to the word "example".
ie:
move $a0, $t3
li $v0, 4
syscall
Prints "example".
How to I move the contents of $t3 into 'word' so that
la $a0, word
li $v0, 4
syscall
Prints "example"
Or, storing it so $s1 has the address of the 'example', such that
la $s1, word
would accomplish.
Thanks in advance! :)
ASKER
...but the value I want written is in a register. I only know what the word to be written is after doing a set of instructions (it fetches an index of strings and puts the correct one in $t3). Is there any way to copy what is in $t3 directly to "word"?
>> Is there any way to copy what is in $t3 directly to "word"?
You don't need to. You can simply do :
move $a0, $t3
li $v0, 4
syscall
Why do you want to reference it as word ?
You don't need to. You can simply do :
move $a0, $t3
li $v0, 4
syscall
Why do you want to reference it as word ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> In any case, I figured it out; below is an example:
?? What's the difference with what I said ?
?? What's the difference with what I said ?
ASKER
You simply printed out $t3.
I transferred $t3 to word and THEN printed it out. (I print $t3 initially to show the value).
I transferred $t3 to word and THEN printed it out. (I print $t3 initially to show the value).
>> I transferred $t3 to word and THEN printed it out.
Yes, but why ? There's no logical reason to do this. In fact, it might cause problems, since you're writing to possibly read-only memory.
I'm not even sure that it'll work - did you test it ? How ?
Yes, but why ? There's no logical reason to do this. In fact, it might cause problems, since you're writing to possibly read-only memory.
I'm not even sure that it'll work - did you test it ? How ?
>> since you're writing to possibly read-only memory.
Not only that, btw, there's a good likelihood that you're overflowing into other memory, since the "test" string is shorter than the "example" string.
Not only that, btw, there's a good likelihood that you're overflowing into other memory, since the "test" string is shorter than the "example" string.
word: .asciiz "test\n"
to :
word: .asciiz "example"