Maximum value in array mips -


i'm trying find maximum value in array , print out value in end.

.globl start .data array:  .word   8,2,31,81,12,10 size:   .word   6 max:    .word 0 .text main: jal start start: lw $t3, size #size la $t1, array # array address lw $s5, ($t1)       # set max, $s5 array[0] add $t1, $t1, 4    # skip array[0] add $t3, $t3, -1       # len = len - 1  loop:  lw $t4, ($t1) # n of array[n]  ble $t4,$s5,l1 #if t4 not less t5 got new max otherwise not. lw $s5, 0($t4) #get element in array  <-- pretty sure im doing wrong here. #sw $s5,0($t1) #max   l1: add $t3, $t3, -1             #counter-1 addi $t1, $t1, 4 # advance array pointer bnez $t3, loop #if not 0 go on , loop  sw $s5, max #printing max val of array lw $a0, max li $v0, 1 syscall   li $v0, 10 

if change lw instruction move s5 var changes value everytime t4 changes value. problem s5 changes everytime t4 changes. move instruction instead of lw max value 10, last element of array.

to clarify: want s5 variable keep value has , change when i've found new max value. @ moment changes everytime t4 changes when use move instruction.

sorry if code looks horrible, new mips i'm pretty clueless.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

django - CSRF verification failed. Request aborted. CSRF cookie not set -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -