So when I call this function for a value in my array, it prints out a garbage value then on the next line what I actually want to print. When I enter a value not in the array it errors out. I am new to this so could be something stupid
.data
array: .word 2,3,1,5,6,7,1,4,8,8 #elements
N: .word 10 # 10 elements
key: .word 0
int: .word 9
search:
la $a0, array
la $t0, N
lw $t0, ($t0)
sll $t0, $t0, 2
addi $t0, $t0, -4
add $a1, $a0, $t0
la $a0, array
jal isort #insert function from other function
li $v0, 4
la $a0, enterKey # Display text
syscall
li $v0,5 # read input
syscall
sw $v0, key
syscall
move $t0, $s0
lw $t1, N
lw $t2, ($t0)
li $t3,0 # $t3 i = 0
lw $t4, int
lw $t5, key
lw $t6, int
loopKey:
beq $t3, $t1, endKey # if i = n, loop ends
bne $t2, $t5, condKey # if the elements are not equal
move $t4, $t3 # assign index found to variable
j endKey
condKey:
addi $t3, $t3, 1 # i++
addi $t0, $t0, 4
lw $t2, ($t0)
j loopKey
endKey:
beq $t4, $t6, noKey #does not appear to even work???
li $v0, 4
la $a0, keyFmsg
syscall
li $v0, 1
add $t4, $t4, 1 # have to add 1 for location not index
add $a0, $zero, $t4 # prints the location
syscall
j displayMenu
noKey: #not working idk why
li $v0, 4
la $a0, keyNFmsg
syscall
j displayMenu