title: mips string copy: error in spim
body: <p>Q1. In my class ppt, that codes are written, but the MIPS code does not work in SPIM. How can I revise the MIPS code?</p>
  
  <p>Q2. Assume that address of x and y are 100 and 200, respectively, and i = 10 and sp = 500. How can I revise MIPS code with that MIPS source code?</p>
  
  <p>//strcpy C code</p>
  
  <pre><code>void strcpy (char x[], char y[]) 
  { 
      int i;
      i = 0;
  
    while ((x[i]=y[i])!='\0')
     i += 1; 
  }
  </code></pre>
  
  <p>//strcpy MIPS code</p>
  
  <pre><code>.data
  
   Array: .space 10
  
  .text
  
  strcpy:
    addi $sp, $sp, -4
    sw $s0, 0($sp)
    add $s0, $zero, $zero
  
  L1: 
    add $t1, $s0, $a1
    lbu $t2, 0($t1)
    add $t3, $s0, $a0
    sb $t2, 0($t3)
    beq $t2, $zero, L2
    addi $s0, $s0, 1
    j L1
  
  L2:
    lw $s0, 0($sp)
    addi $sp, $sp, 4
    jr $ra
  </code></pre>