        # This is just like print_array1, except we lift redundant
        # computation out of the loop.  This is the sort of thing
        # a decent compiler (clang or gcc) will do.
        .data
newline:
        .asciiz "\n"
myArray:
        .word 5 32 87 95 286 386
myArrayLength:
        .word 6

        .text
main:
        # C code:
        #
        # int myArray[] = {5, 32, 87, 95, 286, 386}
        # int myArrayLength = 6
        # int x
        #
        # for (x = 0: x < myArrayLength: x++) {
        #   print(myArray[x])
        #   print("\n")
        # }
        
        # t0: x
        # t1: Value of myArrayLength, which doesn't change during execution
        # t2: Value of &myArray, whose address doesn't change

        # initialize variables
        li $t0, 0
        la $t3, myArrayLength
        lw $t1, 0($t3)
        la $t2, myArray

loop:
        # see if x < myArrayLength, putting result in $t3
        slt $t3, $t0, $t1
        beq $t3, $zero, end_main # jump out if not true

        # figure out where in the array we need to read from.
        # This is going to be the array address + (index << 2).
        # The shift is a multiplication by four to index bytes
        # as opposed to words.  Ultimately, the result is put in $t5
        sll $t3, $t0, 2
        add $t4, $t3, $t2
        lw $t5, 0($t4)
        
        # print it out, with a newline
        li $v0, 1
        move $a0, $t5
        syscall
        li $v0, 4
        la $a0, newline
        syscall
        
        # increment index
        addi $t0, $t0, 1

        # restart loop
        j loop

end_main:
        # exit the program
        li $v0, 10
        syscall
        
