I am trying to create a mips program that will go through 3 if/if-else statements and loop them 10 times. I am having difficulty understanding how to make a label to loop other labels or if there is another method. My code is as follows:
.data
a: .word 10
b: .word 16
c: .word 16
d: .word 6
message: .asciiz "\nThe numbers are equal\n"
message2: .asciiz "\nThe numbers are not equal\n"
.text
lw $s0, a
lw $s1, b
lw $s2, c
lw $s3, d
main:
beq $s0, $s1, firstEqualsStatement
beq $s0, $s1, secondEqualsStatement
j NEXT
bne $s0, $s1, doNotEqualStatement
j NEXT2
firstEqualsStatement: #if (a == b)
#{ Z = a+a;
# Z = Z + b + c + d;
#}
# print message if the numbers are equal
li $v0, 4
la $a0, message
syscall
li $v0, 1
add $a0, $s0, $s0
add $a0, $a0, $s1
add $a0, $a0, $s2
add $a0, $a0, $s3
syscall
secondEqualsStatement: # if (a == b)
#{
# Z = a;
#}
# else
#{
# Z = (a+b+c) – d;
#}
# print message if the numbers are equal
li $v0, 4
la $a0, message
syscall
li $v0, 1
add $a0, $s0, $zero
syscall
NEXT:
li $v0, 4
la $a0, message2
syscall
li $v0, 1
add $a0, $s0, $s1
add $a0, $a0, $s2
sub $a0, $a0, $s3
syscall
doNotEqualStatement: # if (a != b) {
# Z = a;
#}
# else {
# Z = (a+b+c) – d;
#}
# print message if the numbers are not equal
li $v0, 4
la $a0, message2
syscall
li $v0, 1
add $a0, $s0, $zero
NEXT2:
li $v0, 1
add $a0, $s0, $s1
add $a0, $a0, $s2
sub $a0, $a0, $s3
syscall
I hope these tips might help you, as MARS is just an updated version of SPIM (which my professor is making us learn for class right now).
Make a register to hold count & max loops at the beginning
Enclose the main loop in a loop label, then after j NEXT2, include a count increment and b main and beq
Other notes