Я написал простую программу, которая умножает две заданные матрицы и затем печатает результат.
Проблема в том, что он просто не дает никакого вывода, кроме "- программа завершена -".
Нет ошибки тоже. Вот код:
.data
errorMessage: .asciiz "Error: row and column are not equal"
newLine: .asciiz "\n"
r1: .word 4 #Row number of M1
r2: .word 2 #Row number of M2
c1: .word 2 #Column number of M1
c2: .word 8 #Column number of M2
M1: .word 1,2,3,4,5,6,7,8
M2: .word 1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8
C: .space 48
.text
main:
li $v1, 0
lw $a1, M1
lw $a2, M2
li $s0, 0 #This will be the counter of first loop
li $s1, 0 #This will be the counter of second loop
li $s2, 0 #Counter for the C
lw $s3, c2($zero) #column_number_of_M2
lw $s4, c1($zero) #column_number_of_M1
lw $s5, r2($zero) #row_number_of_M2
bne $s4, $s5, notEqual #if (column_number_of_M1 != row_number_of_M2) notEqual();
sub $s0, $s0, 1
jal Matrix_multiply
Matrix_multiply:
addi $s0, $s0, 1 #Increase s0 by 1
bge $s0, $s3, END_FOR #if (s0 >= column_number_of_M2) END_FOR();
li $s1, 0 #reset s1 to 0
jal FOR_LOOP #Go to for loop
FOR_LOOP:
bge $s1, $s3, Matrix_multiply #if s1 >= t4 go to Matrix_multiply
jal Inner_product
mul $t3, $s2, 4 #Multiply the counter with 4
sw $v1, C($t3)
addi $s2, $s2, 1 #Increase the C counter
addi $s1, $s1, 1 #Increase s1 by 1
j FOR_LOOP #Jump back to the top to loop again
END_FOR:
beq $t0, 128, exit
lw $t6, C($t0)
addi $t0, $t0, 4
#Print current number
li $v0, 1
move $a0, $t6
syscall
#Print a new line
li $v0, 4
la $a0, newLine
syscall
j END_FOR
exit:
li $v0, 10
syscall
Inner_product:
li $t0, 0 #reset t0 to 0
li $t1, 0 #reset t1 to 0
addi $t0, $s0, 1
addi $t1, $s1, 8
mul $t0, $t0, 4
mul $t1, $t1, 4
mul $t2, $s0, 4
mul $t3, $s1, 4
#$v0 = M1[$s0] * M2[$s1] + M1[$t0] * M2[$t1];
lw $t5, M1($t2)
lw $t6, M2($t3)
mul $v1, $t5, $t6
lw $t5, M1($t0)
lw $t6, M2($t1)
mul $t4, $t5, $t6
add $v1, $v1, $t4
jr $ra
notEqual: #print error then exit
li $v0, 4
la $a0, errorMessage
syscall
Редактировать: я обновил код благодаря комментарию @Jester. Сейчас есть выход, но он далек от правильного.