You are on page 1of 1

; load the first element of the array into $4 lw $4, 0($1) ; load 1 into $5 (for comparison in slt) lis

$5 .word 1 ; load length of array - 1 into 2 sub $2, $2, $5 ; load 4 into $6 lis $6 .word 4 ; load 0 into $7 ($7 is the counter) lis $7 .word 0 ; quadruple $7 mult $7, $6 ; load quadruple $7 into $8 mflo $8 ; add the base address to $8 add $8, $8, $1 ; load the memory at $8 into $9 lw $9, 0($8) ; compare $9 (the current part of the array) with $4 (the stored largest part of the array) and store result in $10 slt $10, $9, $4 ; branch if $10 = $9 = 1 (the current part is smaller than the stored largest) beq $5, $10, 1 ; put $9 in $4 add $4, $9, $0 ; branch if at the end of the array beq $2, $7, 2 ; add 1 to the counter $7 add $7, $7, $5 ; go back to the quadruple 5 beq $5, $5, -10 ; put whatever is in $4 (the stored largest) into $3 add $3, $4, $0 ; return jr $31

You might also like