# By positioning our data in the range from 10000000-1000ffff, we # make it easier to access, by using 16-bit offsets from $gp. .data 0x10000000 # POSITION AT START OF DATA SEGMENT # Array of seven words to sort. data: .word 0x34, 0x21, 0x74, 0x12, 0x94, 0x22, 0x87, 0x26 .text # ENTER TEXT SEGMENT main: la $s1,data # Point $s1 at the data array li $s2,8 # Initialize $s2 to # elements # Max algorithm starts here lw $t0,0($s1) # initialize maximum to A[0] addi $t1,$zero,0 # initialize index i to 0 loop: add $t1,$t1,1 # increment index i by 1 beq $t1,$s2,done # if all elements examined, quit add $t2,$t1,$t1 # compute 2i in $t2 add $t2,$t2,$t2 # compute 4i in $t2 add $t2,$t2,$s1 # form address of A[i] in $t2 lw $t3,0($t2) # load value of A[i] into $t3 slt $t4,$t0,$t3 # maximum < A[i]? beq $t4,$zero,loop # if not, repeat with no change addi $t0,$t3,0 # if so, A[i] is the new maximum j loop # change completed; now repeat done: jr $ra # continuation of the program