所以我有这段代码可以读取一个双精度数组并进行高斯消除,我想将其更改为读取浮点数,我的问题是如果我将数组更改为浮点数,我需要更改什么以使我的程序继续运行。
我知道我的数组应该更改为 .float 并且在浮点数中我需要使用 li $v0、2 和 lcw1 $f12,并且我正在使用 li $v0、3 ldc1 $f2,但我一直在更改它并给了我错误的答案我不知道该怎么做,我正在尝试,但我不能让它工作任何帮助PLZ?
### Text segment
.eqv n 3
.text
main:
la $a0, array
li $a1, n
jal print_matrix
nop
jal gauss_reduct
nop
la $a2, solution
jal gauss_solve
nop
jal print_solution
nop
exit:
li $v0, 10
syscall
gauss_reduct:
addiu $sp, $sp, -24
sw $ra, 20($sp)
sw $s2, 16($sp)
sw $s1, 12($sp)
sw $s0, 8($sp)
sw $a1, 4($sp)
sw $a0, 0($sp)
add $t3, $a0, $zero
addi $t4, $a1, -1
addi $t5, $a1, 0
add $t2, $zero, $zero
gauss_reduct_ciclok:
beq $t2, $t5, gauss_reduct_end
nop
add $t1, $zero, $zero
gauss_reduct_cicloj:
beq $t1, $t5, gauss_reduct_fim_ciclo_j
nop
beq $t1,$t2,gauss_reduct_cicloj_continue
nop
move $a0, $t1
move $a1, $t2
jal fetchaddress
nop
move $s1, $v0
ldc1 $f6,($s1)
move $a0, $t2
move $a1, $t2
jal fetchaddress
nop
move $s1, $v0
ldc1 $f8,($s1)
div.d $f4,$f6,$f8
add $t0,$zero,$zero
move $a0, $t1
move $a1, $t0
jal fetchaddress
nop
move $s1, $v0
move $a0, $t2
move $a1, $t0
jal fetchaddress
nop
move $s2, $v0
gauss_reduct_cicloi:
bgt $t0, $t5,gauss_reduct_fim_ciclo_i
nop
ldc1 $f6,($s1)
ldc1 $f8,($s2)
mul.d $f8,$f8,$f4
sub.d $f6,$f6,$f8
sdc1 $f6,($s1)
addiu $t0,$t0,1
addiu $s1,$s1,8
addiu $s2,$s2,8
j gauss_reduct_cicloi
nop
gauss_reduct_fim_ciclo_i:
gauss_reduct_cicloj_continue:
addiu $t1,$t1,1
j gauss_reduct_cicloj
nop
gauss_reduct_fim_ciclo_j:
addiu $t2,$t2,1
j gauss_reduct_ciclok
nop
gauss_reduct_end:
lw $ra, 20($sp)
lw $s2, 16($sp)
lw $s1, 12($sp)
lw $s0, 8($sp)
lw $a1, 4($sp)
lw $a0, 0($sp)
addiu $sp, $sp, 24
jr $ra
nop
gauss_solve:
addiu $sp, $sp, -24
sw $ra, 20($sp)
sw $s2, 16($sp)
sw $s1, 12($sp)
sw $s0, 8($sp)
sw $a1, 4($sp)
sw $a0, 0($sp)
add $t3, $a0, $zero
addi $t0, $a1, -1
addi $t5, $a1, 0
sll $s1, $t4, 3
addu $s1, $s1, $a2
addi $t0, $t4, 0
gauss_solve_cicloi:
blt $t0, $zero, gauss_solve_end
nop
# v0 = &A[i][n]
move $a0, $t0
move $a1, $t5
jal fetchaddress
nop
# $f6 = A[i][n]
ldc1 $f6,($v0)
# X[i] = A[i][n]
sdc1 $f6,($s1)
addi $t1, $t0, 1
sll $s2, $t1, 3
add $s2, $s2, $a2
gauss_solve_cicloj:
beq $t1, $t5, gauss_solve_fim_cicloi
nop
# v0 = &A[i][j]
move $a0, $t0
move $a1, $t1
jal fetchaddress
nop
ldc1 $f8,($v0)
ldc1 $f4,($s2)
mul.d $f8,$f8,$f4
sub.d $f6,$f6,$f8
sdc1 $f6,($s1)
addi $t1,$t1,1
addi $s2, $s2, 8
j gauss_solve_cicloj
nop
gauss_solve_fim_cicloi:
# v0 = &A[i][i]
move $a0, $t0
move $a1, $t0
jal fetchaddress
nop
# $f8 = A[i][i]
ldc1 $f8,($v0)
# x[i] = x[i] / A[i][i];
div.d $f6,$f6,$f8
sdc1 $f6,($s1)
subi $t0,$t0,1
subi $s1, $s1, 8
j gauss_solve_cicloi
nop
gauss_solve_end:
lw $ra, 20($sp)
lw $s2, 16($sp)
lw $s1, 12($sp)
lw $s0, 8($sp)
lw $a1, 4($sp)
lw $a0, 0($sp)
addiu $sp, $sp, 24
jr $ra
nop
fetchaddress:
addiu $t5,$t5,1
multu $a0, $t5
subiu $t5,$t5,1
mflo $v0
add $v0, $v0, $a1
sll $v0, $v0, 3
add $v0, $v0, $t3
jr $ra
nop
print_matrix:
addiu $sp, $sp, -24
sw $ra, 20($sp)
sw $s2, 16($sp)
sw $s1, 12($sp)
sw $s0, 8($sp)
sw $a2, 4($sp)
sw $a0, 0($sp)
move $s2, $a0
move $s1, $zero
loop_s1:
addi $a2,$a1,1
move $s0, $zero
loop_s0:
l.d $f12, 0($s2)
li $v0, 3
syscall
la $a0, spaces
li $v0, 4
syscall
addiu $s2, $s2, 8
addiu $s0, $s0, 1
blt $s0, $a2, loop_s0
nop
la $a0, newline
syscall
addiu $s1, $s1, 1
blt $s1, $a1, loop_s1
nop
la $a0, newline
syscall
lw $ra, 20($sp)
lw $s2, 16($sp)
lw $s1, 12($sp)
lw $s0, 8($sp)
lw $a2, 4($sp)
lw $a0, 0($sp)
addiu $sp, $sp, 20
jr $ra # return
nop
print_solution:
li $v0, 4 #display a mensagem
la $a0, Solution
syscall
li $v0, 4 #display a mensagem
la $a0, newline
syscall
addiu $sp, $sp, -24
sw $ra, 20($sp)
sw $s2, 16($sp)
sw $s1, 12($sp)
sw $s0, 8($sp)
sw $a2, 4($sp)
sw $a0, 0($sp)
move $s1, $zero
move $s2, $a2
print_solution_loop_s0:
ldc1 $f12, ($s2)
li $v0, 3
syscall
addiu $s2, $s2, 8
addiu $s1, $s1, 1
la $a0, newline
li $v0, 4
syscall
blt $s1, $a1, print_solution_loop_s0
nop
lw $ra, 20($sp)
lw $s2, 16($sp)
lw $s1, 12($sp)
lw $s0, 8($sp)
lw $a2, 4($sp)
lw $a0, 0($sp)
addiu $sp, $sp, 20
jr $ra
nop
### End of text segment
### Data segment
.data
array: .double
2.0, 1.0, -3.0, -1.0,
-1.0, 3.0, 2.0, 12.0,
3.0, 1.0, -3.0, 0.0
### String constants
spaces:
.asciiz " "
newline:
.asciiz "\n"
Solution:.asciiz "Solution:"
solution:
.double 0.0
.double 0.0
.double 0.0
.double 0.0
### End of data segment