We help IT Professionals succeed at work.

Easy question? Storing a register in MIPS to a predefined "asciiz" word.

sprockston
sprockston asked
on
814 Views
Last Modified: 2008-08-12
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! :)
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2009

Commented:
Just change :

        word:      .asciiz "test\n"

to :

        word:      .asciiz "example"

Author

Commented:
...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"?
CERTIFIED EXPERT
Top Expert 2009

Commented:
>> 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 ?
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2009

Commented:
>> In any case, I figured it out; below is an example:

?? What's the difference with what I said ?

Author

Commented:
You simply printed out $t3.
I transferred $t3 to word and THEN printed it out. (I print $t3 initially to show the value).
CERTIFIED EXPERT
Top Expert 2009

Commented:
>> 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 ?
CERTIFIED EXPERT
Top Expert 2009

Commented:
>> 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.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.