        .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

        # initialize x
        li $t0, 0

loop:
        # get myArrayLength, putting the result in $t2
        la $t1, myArrayLength  # $t1 = &myArrayLength
        lw $t2, 0($t1)

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

        # get the base of myArray
        la $t4, myArray

        # 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 $t7
        sll $t5, $t0, 2
        add $t6, $t5, $t4
        lw $t7, 0($t6)
        
        # print it out, with a newline
        li $v0, 1
        move $a0, $t7
        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
        
