Confusion in MIPS code

Posted by Haya Hallian on Stack Overflow See other posts from Stack Overflow or by Haya Hallian
Published on 2012-10-02T04:43:33Z Indexed on 2012/10/02 9:37 UTC
Read the original article Hit count: 190

Filed under:
|
|

While going through the MIPS code I got some confusion. Code is shown as follows

.data
 key: .ascii "key: "              # "key:  \n"
char: .asciiz "  \n"               
 .text
 .globl main
main:
 jal getchar     

la $a0, char                    # $a0 contains address of char variable (" \n")
  sb $v0, ($a0)                   # replace " " in char with v0, which is read_character (X) 
 la $a0, key                     # now a0 will contain, address of "key: "  "X\n"

What I dont understand is that how load address instruction works. First a0 contained address of char variable. In next line we are storing value of v0 in that location. there is no offset with ($a0), is that assumed to be 0 like in 0($a0)? Why only the " " empty space is replaced with v0, and why not the "\n" get replaced? or It may also have been the case that both the empty space and \n character get replced by v0.

Secondly when we load the address of key in a0, the previous address should be overwritten. a0 should have contained the address of key only, but from comment it seems that the two strings are concatenated. How does that happen.

© Stack Overflow or respective owner

Related posts about load

Related posts about mips