diff --git a/prj1.asm b/prj1.asm index 4bb63d6..984591e 100644 --- a/prj1.asm +++ b/prj1.asm @@ -37,26 +37,23 @@ lookup: addi $t0, $a2, 1 # store one higher value # loop to find index - beq $s0, $t0, setoob # jump to oob function if we overrun array + bne $s0, $t0, dsetoob # set out of bounds if we overrun array + li $s0, -1 # index is oob, set to -1 + jr $ra # jump back to ra in main + dsetoob: # label for if we dont want to set oob # find current array value - addi $t1, $s0, 0 # load index into $t1 - sll $t1, $t1, 2 # multiply the offset - add $t1, $t1, $a0 # add the offset to the base address - lw $t2, 0($t1) # get current array value: aka arr[$s0] + addi $t1, $s0, 0 # load index into $t1 + sll $t1, $t1, 2 # multiply the offset + add $t1, $t1, $a0 # add the offset to the base address + lw $t2, 0($t1) # get current array value: aka arr[$s0] - beq $a1, $t2, setval # check if this is the value we are looking for - addi $s0, $s0, 1 # incriment counter - j lookup # back to beginning of loop + bne $a1, $t2, dontjump # check if this is the value we are looking for + jr $ra # return to main function if the values match + dontjump: # continue loop if they match + addi $s0, $s0, 1 # incriment counter + j lookup # back to beginning of loop -# set value function -setval: - jr $ra - -# set out of bounds function -setoob: - li $s0, -1 # index is oob, set to -1 - jr $ra # jump back to ra in main .data