From d602e8768549a601bdc7ebcee0c739969a12ae30 Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Mon, 17 Feb 2020 14:30:46 +0000 Subject: [PATCH] Move oob/value function into lookup function This dosen't help readability but cleans up the code a little --- prj1.asm | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) 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