# Finds the maximum number in an array of 8 non-negative 1-word integers and stores it in $a2 .text main: la $a0, array1 # $a0 pointer to the array addi $a1, $zero, 8 # $a1 = number of elements in array jal maximum # "maximum" function call j finish ## maximum function maximum: addi $t0, $a0, 0 # $t0 points to the array addi $t7, $zero, 0 # $t7 index = 0 addi $t2, $zero, 0 # maxSoFar = 0 maximum_loop: # if index == number of elements in the array, exit loop beq $t7, $a1, maximum_finish lw $t3, 0($t0) # $t3 = array1[index] slt $t1, $t3, $t2 # if array1[index] < maxSoFar then $t1 = 1 bne $t1, $zero, notmore # if $t1 == 1, then don't update maxSoFar addi $t2, $t3, 0 # maxSoFar = array1[index] notmore: addi $t7, $t7, 1 # index = index + 1 addi $t0,$t0, 4 # point to the next element of the array j maximum_loop maximum_finish: jr $ra finish: addi $a2, $t2, 0 # $a2 now has maximum element .data .align 2 array1: .word 3,5,7,9,10,8,6,4