# Print the values of an array until a zero value is found. # # We use an index variable ($t1) that goes from # 0 to 2. During each loop iteration we load the # i:th array element, array[i], using the addressing # mode # array + 0($t2) # $t2 holds the offset of the i:the element # (i.e. 4*i) from the beginning of the array, # so the addressing mode computes # address(array) + i*4, # which is the address of array[i]. # We use sll to multiply by 4, since this is faster # than mul. .data array: .word 55 .word 66 .word 77 .word 0 nl: .asciiz "\n" .text # $t1 holds array index # $t2 holds array index * 4 # $a0 holds current array element value main: li $t1,0 # array index loop: sll $t2,$t1,2 # array elements are 4 bytes lw $a0,array + 0($t2) # Load data value beq $a0,0,done # while ($a0!=0) do li $v0,1 # print data value syscall la $a0,nl # print nl li $v0,4 syscall add $t1,1 # index++ b loop # end while done: li $v0,10 # exit syscall