过去13个小时我一直试图完成这个程序。我已经尝试了一切,似乎没有任何工作。出于某种原因,当我从用户那里获取4x4矩阵的输入并将它们相乘时,它会起作用。当我尝试计算已经初始化的两个8x8矩阵的乘积时,它给出了错误的答案。
初始化矩阵;
array1: .byte 1,3,4,7,8,8,9,4,3,2,3,32,3,4,5,6,7,8,9,8,6,4,5,4,4,3,5,6,7,7,8,7,5,4,3,4,5,6,5,4,5,4,5,6,7,8,8,9,5,3,3,2,4,6,7,8,3,2,2,1,3,4,5,6,7,7,5,4,3,4,5,4,4,3,3,4,3,3,4,3,3,34,5,5,6,7,7,8,6,5,4,4,3,3,5,6,7
array2: .byte 0,4,4,7,6,6,4,4,4,7,4,7,4,4,7,6,7,6,4,6,6,4,0,4,4,4,7,6,7,7,6,7,7,4,7,4,7,6,7,4,7,4,6,6,7,6,6,4,7,4,4,7,4,6,7,7,4,7,7,4,4,4,7,6,7,7,7,4,4,4,7,4,44,4,4,4,7,4,4,4,4,44,7,7,6,7,7,6,7,7,4,4,4,4,7,6,7
将它们相乘的代码;
la $t2, array3
la $t3, array2
la $a1, array1
li $s1, 0
li $a2, 8
L1: # First Row of Product Matrix complete. Start second row of product matrix
li $s2, 0
L2:
li $s3, 0
sll $t1, $s1, 3
addu $t1, $s2, $t1
addu $t1, $t2, $t1
lbu $s4, ($t1)
L3:
sll $t4, $s3, 3
addu $t4, $t4, $s2
addu $t4, $t4, $t3
lbu, $t5, ($t4)
sll $t6, $s1, 3
addu $t6, $t6, $s3
addu $t6, $t6, $a1
lbu $t7, ($t6)
mul $t5, $t7, $t5
addu $s4, $s4, $t5
addiu $s3, $s3, 1
bne $s3, $a2, L3
sb $s4, ($t1)
addiu $s2, $s2, 1
bne $s2, $a2, L2
addiu $s1, $s1, 1
bne $s1, $a2, L1 # First row of product matrix is complete.
addiu $a0, $zero, 10
li $v0,11
syscall
la $s7, Productmatrixmessage
move $a0, $s7
li $v0, 4
syscall
addiu $a0, $zero, 10
li $v0,11
syscall
la $t2, array3
li $t6, 8
li $s4, 1
li $t4, 65
li $t5, 0
li $t7, 1
la $a0, Outputrowmessage
li $v0, 4
syscall
li $a0, 1
li $v0, 1
syscall
la $a0, colon
li $v0, 4
syscall
outputproductmatrix:
beq $s4, $t4, Productmatrixend
la $a0, space
li $v0, 4
syscall
lbu $a0, ($t2)
li $v0, 1
syscall
addiu $t2, $t2, 1
addiu $t5, $t5, 1
addiu $s4, $s4, 1
beq $t5, $t6, newline
j outputproductmatrix
newline:
beq $s4, $t4, Productmatrixend
addi $t7, $t7, 1
li $t5, 0
addiu $a0, $zero, 10
li $v0,11
syscall
la $a0, Outputrowmessage
li $v0, 4
syscall
move $a0, $t7
li $v0, 1
syscall
la $a0, colon
li $v0, 4
syscall
j outputproductmatrix
Productmatrixend: