Browse Source

Move oob/value function into lookup function

This dosen't help readability but cleans up the code a little
develop
Matthew Faltys 5 years ago
parent
commit
d602e87685
  1. 29
      prj1.asm

29
prj1.asm

@ -37,26 +37,23 @@ lookup:
addi $t0, $a2, 1 # store one higher value addi $t0, $a2, 1 # store one higher value
# loop to find index # 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 # find current array value
addi $t1, $s0, 0 # load index into $t1 addi $t1, $s0, 0 # load index into $t1
sll $t1, $t1, 2 # multiply the offset sll $t1, $t1, 2 # multiply the offset
add $t1, $t1, $a0 # add the offset to the base address add $t1, $t1, $a0 # add the offset to the base address
lw $t2, 0($t1) # get current array value: aka arr[$s0] 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 bne $a1, $t2, dontjump # check if this is the value we are looking for
addi $s0, $s0, 1 # incriment counter jr $ra # return to main function if the values match
j lookup # back to beginning of loop 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 .data

Loading…
Cancel
Save