所以,我正在输入两个数组并打印其中一个(现在),但是当我去打印其中一个数组时,它会打印一个数组的一些值和另一个数组的一些值。我不知道为什么会这样。请帮忙。这是我的代码,然后是示例输出:
.data
title: .asciiz "Find The Product of Two Matrices\n\n"
menuString: .asciiz "Menu\n\n"
option1: .asciiz "1. Enter values and find product\n"
option2: .asciiz "2. Exit program\n\n"
inputString: .asciiz "Enter selection: "
promptSize: .asciiz "\nEnter row size of square matrix: "
promptRow: .asciiz "Row: "
promptCol: .asciiz "Col: "
promptMatrix1Float: .asciiz "Enter a first matrix's float: "
promptMatrix2Float: .asciiz "Enter a second matrix's float: "
answer: .asciiz " Answer:"
printFloat: .asciiz "\nA Float: "
inputFirstMatrix: .asciiz "\n\nInput First Matrix(left-to-right and top-to-bottom):\n\n"
inputSecondMatrix: .asciiz "\n\nInput Second Matrix(left-to-right and top-to-bottom):\n\n"
.globl main
.text
################################### INPUT SIZE AND MATRICES ####################
size: li $v0, 4
la $a0, promptSize
syscall
li, $v0, 5
syscall
add $t1, $v0, $v0
li $t0, 0
li $v0, 4
la $a0, inputFirstMatrix
syscall
L1: beq $t0, $t1, L2IndexInit
li $v0, 4
la $a0, promptMatrix1Float
syscall
li $v0, 6 #6 is the syscall code for get float
syscall
sll $t3, $t0, 3
add $t3, $a2, $t3
s.d $f0, 0($t3) # Store $f0 at memory location .
addi $t0, $t0, 1
j L1
L2IndexInit:
li $v0, 4
la $a0, inputSecondMatrix
syscall
li $t0, 0
L2: beq $t0, $t1, PrintIndexInit
li $v0, 4
la $a0, promptMatrix2Float
syscall
li $v0, 6 #6 is the syscall code for get float
syscall
sll $t3, $t0, 3
add $t3, $a1, $t3
s.d $f0, 0($t3) # Store $f0 at memory location .
addi $t0, $t0, 1
j L2
############################## PRINT MATRIX #################################################
PrintIndexInit:
li $t0, 0
PrintMatrix: beq $t0, $t1, End
sll $t4, $t0, 3
add $t4, $a2, $t4
l.d $f12, 0($t4)
li $v0, 4
la $a0, printFloat
syscall
li $v0, 2 #2 is the syscall code for print float (arg. to print in f12)
syscall
addi $t0, $t0, 1
j PrintMatrix
####################################### MAIN FUNCTION AND END ######################
End:
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
main:
li $v0, 4
la $a0, title
syscall
addi $sp, $sp, -4
sw $ra, 0($sp)
jal size
li $v0, 10
syscall
示例输出:
求两个矩阵的乘积 输入方阵的行大小:2 输入第一个矩阵(从左到右和从上到下): 输入第一个矩阵的浮点数:2.3 输入第一个矩阵的浮点数:4.3 输入第一个矩阵的浮点数:6.5 输入第一个矩阵的浮点数:4.3 输入第二个矩阵(从左到右和从上到下): 输入第二个矩阵的浮点数:3.2 输入第二个矩阵的浮点数:6.5 输入第二个矩阵的浮点数:8.9 输入第二个矩阵的浮点数:3.2 一个浮点数:6.50000000 一个浮点数:8.89999962 一个浮点数:3.20000005 一个浮点数:4.30000019