title: Printing arrays of strings in MIPS
body: <p>I'm working on a program that's supposed to accept input (numbers 1-9) from the user, and then use that input to print completed MIPS instructions (with 1 = add, 2 = addi, 3 = or, etc.). </p>
  
  <p>An example of this would be that the user inputs the number 1, and the program outputs "<code>add $t2, $t0, $t1</code>". The user inputs the number 2, and the program outputs "<code>addi $t3, $t2, 100</code>" (the registers are both consecutive and linked).</p>
  
  <p>So, as seen above, one function of the program is to iterate through registers <code>$t0-$t9</code> as the user inputs numbers. I thought that the best way to print out these registers along with their associated opcode would be to put them in an array and cycle through them. However, I can't find out if/how MIPS prints out arrays of strings (and yes, I saw the other stackoverflow post asking the same question, but I don't quite understand the answer because it's written in C). </p>
  
  <p>I would really appreciate any help people are able to give!</p>
  
  <p>This is the relevant part of my code (I know it's not much, sorry):</p>
  
  <pre><code>.data
  registers: .asciiz "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7", "$t8", "$t9"  #this is the array that I want to print
  registerSize: .word 9
  
  .text 
  readOpcodes:    #read the user-entered ints (1-9) in preparation for numberDecisions
  add $t0, $t0, $zero
  lb $s0, opcodes($t0)
  
  numberDecisions:    #decide which instruction to output based on user input
  beq $s0, 1, addOpcode 
  beq $s0, 2, addiOpcode 
  beq $s0, 3, orOpcode 
  beq $s0, 4, oriOpcode
  beq $s0, 5, lwOpcode
  beq $s0, 6, swOpcode
  beq $s0, 7, jOpcode
  beq $s0, 8, beqOpcode
  beq $s0, 9, bneOpcode 
  
  registerAllocation: #this is all I've really got when it comes to printing out the register array
  addi $s1, $zero, 0  #register counter = 0
  la $s2, registers   #load register array in $s2
  la $s3, registerSize    #load register array size into $s3
  
  addOpcode:
  li $v0, 4   #print 'add' opcode
  la $a0, addPrint
  syscall
  
  addi $t0, $t0, 1
  beq $t0, 5, end
  j readOpcodes    #Ideally, I'd be able to print the registers (in the proper order depending on the opcode, obviously) in this section for each opcode
  
  addiOpcode:  #feel free to ignore the rest; it's just the process of printing all 9 opcodes. Sorry if it's not completely relevant, but I wasn't sure how clear my code would be if I left it all out
  li $v0, 4   #print 'addi' opcode
  la $a0, addiPrint
  syscall
  
  addi $t0, $t0, 1
  beq $t0, 5, end
  j readOpcodes
  
  orOpcode:
  li $v0, 4   #print 'or' opcode
  la $a0, orPrint
  syscall
  
  addi $t0, $t0, 1
  beq $t0, 5, end
  j readOpcodes
  
  oriOpcode:
  li $v0, 4   #print 'ori' opcode
  la $a0, oriPrint
  syscall
  
  addi $t0, $t0, 1
  beq $t0, 5, end
  j readOpcodes
  
  lwOpcode:
  li $v0, 4   #print 'lw' opcode
  la $a0, lwPrint
  syscall
  
  addi $t0, $t0, 1
  beq $t0, 5, end
  j readOpcodes 
  
  swOpcode:
  li $v0, 4   #print 'sw' opcode
  la $a0, swPrint
  syscall
  
  addi $t0, $t0, 1
  beq $t0, 5, end
  j readOpcodes
  
  jOpcode:
  li $v0, 4   #print 'j' opcode
  la $a0, jPrint
  syscall
  
  addi $t0, $t0, 1
  beq $t0, 5, end
  j readOpcodes
  
  beqOpcode:
  li $v0, 4   #print 'beq' opcode
  la $a0, beqPrint
  syscall
  
  addi $t0, $t0, 1
  beq $t0, 5, end
  j readOpcodes
  
  bneOpcode:
  li $v0, 4   #print 'bne' opcode
  la $a0, bnePrint
  syscall 
  
  addi $t0, $t0, 1
  beq $t0, 5, end
  j readOpcodes
  
  end: 
  li $v0, 10
  syscall
  </code></pre>