# Print the values of an array until a zero value is found. # # Here we have an index variable ($t1) that goes from # 0 to 2. During each loop iteration we compute the # address of the i:th array element, array[i], namely # addr(array)+4*i. We can then load the value stored # at that address. .data array: .word 55 .word 66 .word 77 .word 0 nl: .asciiz "\n" .text # $t0 holds array base address # $t1 holds array index # $t2 holds current array element address # $a0 holds current array element value main: li $t1,0 # array index loop: la $t0,array # base address of array mul $t2,$t1,4 # array elements are 4 bytes add $t2,$t2,$t0 # t2=addr(array)+index*4 lw $a0,($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