so I have an issue with my program. I have a for loop with a bunch of multi conditional if statements in it and when it runs, it is giving me an infinite loop. This is the portion of the whole program where the loop is happening
li $t7, 0 # i=0
bge $t7, $s0, exit_i # i < trackHeight
addi $t7, $t7, 1 # i++
# j forDraw_1 # loop while i=0
i_plus:
li $t8, 0 # j=0
bge $t8, $s1, exit_j # j < trackWidth
addi $t8, $t8, 1 # j++
# j i_plus # loop while j=0
# j_plus:
if_1:
beq $t7, $zero, drawBorder # i==0
beq $t8, $zero, drawBorder # j==0
addi $t9, $s0, -1 # trackHeight -1
beq $t7, $t9, drawBorder # i== t.h -1
addi $t5, $s1, -1 # trackWidth -1
beq $t8, $t5, drawBorder # j== t.w -1
# else if 1
beq $t7, $s2, draw219 # i == x
beq $t8, $s3, draw219 # j == y
# else if 2
#beq $t7, $s2, draw219 # i == x
addi $t4, $s3, -1 # y-1
beq $t8, $t4, draw219 # j == y-1
# else if 3
#beq $t7, $s2, draw56 # i == x
addi $t4, $t4, 2 # y-1 --> y+1
beq $t8, $t4, draw56 # j == y+1
# else if 4
addi $t3, $s2, 1 # x+1
beq $t7, $t3, draw254 # i == x+1
#addi $t4, $t4, -1 # j back to 0
#beq $t8, $s3, draw254 # j == y
# else if 5
addi $t3, $t3, -2 # x+1 --> x-1
beq $t7, $t3, draw127 # i == x-1
#beq $t8, $s3, draw127 # j == y
# else if 6
addi $t4, $zero, 10
ble $t8, $zero, printLane # j>0
div $t8, $t4
mfhi $t5
beqz $t5, printLane
drawBorder:
li $v0, 4
la $a0, outsideBorder
syscall
j if_1
printLane:
li $v0, 4
la $a0, lanes
syscall
draw219:
li $t5, 219
move $a0, $t5
li $v0, 11
syscall
draw56:
li $t5, 56
move $a0, $t5
li $v0, 11
syscall
draw254:
li $t5, 254
move $a0, $t5
li $v0, 11
syscall
draw127:
li $t5, 127
move $a0, $t5
li $v0, 11
syscall
I also tried writing it in a different format, but also got an infinite loop. This is the other format. Not sure what is wrong, but i have a strong feeling it is coming from the initialization of the loop
bne $t7, $zero, else_if1 # i==0
bne $t8, $zero, else_if1 # j==0
addi $t9, $s0, -1 # trackHeight -1
bne $t7, $t9, else_if1 # i== t.h -1
addi $t5, $s1, -1 # trackWidth -1
bne $t8, $t5, else_if1 # j== t.w -1
li $v0, 4
la $a0, outsideBorder
syscall
else_if1:
bne $t7, $s2, else_if2 # i == x
bne $t8, $s3, else_if2 # j == y
li $t5, 219
move $a0, $t5
li $v0, 11
syscall
else_if2:
beq $t7, $s2, else_if3 # i == x
addi $t4, $s3, -1 # y-1
bne $t8, $t4, else_if3 # j == y-1
li $t5, 219
move $a0, $t5
li $v0, 11
syscall
else_if3:
beq $t7, $s2, else_if4 # i == x
addi $t4, $t4, 2 # y-1 --> y+1
bne $t8, $t4, else_if4 # j == y+1
li $t5, 56
move $a0, $t5
li $v0, 11
syscall
else_if4:
addi $t3, $s2, 1 # x+1
bne $t7, $t3, else_if5 # i == x+1
#addi $t4, $t4, -1 # j back to 0
beq $t8, $s3, else_if5 # j == y
li $t5, 254
move $a0, $t5
li $v0, 11
syscall
else_if5:
addi $t3, $t3, -2 # x+1 --> x-1
bne $t7, $t3, else_if6 # i == x-1
beq $t8, $s3, else_if6 # j == y
li $t5, 127
move $a0, $t5
li $v0, 11
syscall
else_if6:
addi $t4, $zero, 10
ble $t8, $zero, printLane # j>0
div $t8, $t4
mfhi $t5
beqz $t5, printLane
li $v0, 4
la $a0, lanes
syscall