title: Why is this MIPS assembly language code crashing my SPIM simulator?
body: <p>In case the comments aren't too clear I'll describe what this is supposed to do. Takes two arrays of length 8 and multiplies each corresponding element and stores the product into a new array. In other words, for array1 [1,2,...,8] and array2 [1,2,...,8] the contents of array 3 will equal [1,4,...,64].</p>
  
  <pre><code>    .data
  array1:     .byte 2, 2, 2, 2, 2, 2, 2, 2
  array2:     .byte 41, 3, 5, 7, 19, 2, 4, 4
  array3:     .space 40 #This must be declared this way
  result:     .asciiz "Product = "
      .globl main
  
      .text
  main:
      la  $s0, array1             #Load address of array1 to s0
      la  $s1, array2             #Load address of array2 to s1
      la  $s2, array3             #Load address of array3 to s2
      lb  $t0, 0($s0)             #Load first byte of array1 to t0
      lb  $t1, 0($s1)             #Load first byte of array2 to t1
      li  $t8, 8                  #Load 8 to t0 for our loop. We'll call it N
  
  loop:
      beq $t0, 0, next        #if the variable X is 0, go to next, else
      add $t2, $t1, $t2       #add t2 and Y, store in t2
      addi $t0, $t0, -1       #decrement X
      j loop                  #jump to loop
  
  next:
      sw $t2, 0($s2)          #Store the product into array3 as a word.
      li $t2, 0               #Load 0 to t2 to reset it before jumping back to loop
      addi $t8, $t8, -1       #decrement t8
      add  $s0, $s0, 1        #Shift to next byte in array1
      lb  $t0, 0($s0)         #Load first byte of array1 to t0
      add  $s1, $s1, 1        #Shift to next byte in array2
      lb  $t1, 0($s1)         #Load first byte of array2 to t1
      add  $s2, $s2, 4        #Shift to next word in array3
      bne  $t8, 0, loop       #If t8 is not yet 0 (we haven't interated through all elements of the list), go to loop.
      li $t8, 8               #Load 8 to t8
      add  $s2, $s2, -32      #Shift to first word of array3
      j print1                    #jump to print procedure
  
  print1:
      li $v0, 4               #load system call code for print string
      la $a0, result          #Load address of result to a0
      syscall                 #print result
      j print2                #jump to print2 procedure
  
  print2:
      li $v0, 1                   #Load system call for print integer
      lw $a0, 0($s2)              #Load first word of array3 to a0
      syscall                     #print Integer
      bne $t8, 0, print2          #if t8 is not equal to 8, loop to print2 procedure
      j close                     #Else jump to close
  
  close:
      li $v0, 10                  #load system call code for terminate
      syscall                     #return control to system
  </code></pre>