The program should take into account the following functionality: The 2D array with the system to solve is passed to the program as an existing variable memory. - The data is of type double float. -The program should save the result in another variable. -The program should show the system of linear equations , before being resolved and in the end shouldshow the solution.
I did this code that shows the matrix:
.text
ldc1 $f30, double.zero($0)
ldc1 $f28, double.um($0)
ldc1 $f26, ajuste.ID($0)
la $a0,comeco
li $v0,4
syscall
la $a1,matrizA
jal build
la $a1, matrizAinv
lw $a2, importante($0)
jal buildID
la $a0,imprimirA
li $v0,4
syscall
la $a1,matrizA
jal printmatrix
la $a0,matrizA
lw $a1,importante($0)
la $a2,matrizA2
jal copia_matriz
la $a0,imprimirID
li $v0,4
syscall
la $a1,matrizAinv
lw $a2,importante($0)
jal printmatrix
li $v0,10 #Fim
syscall
build:
la $a0, dimensao
li $v0, 4
syscall
li $v0, 5
syscall
sw $v0, importante($0)
move $t0, $v0
move $t2, $zero
move $t3, $zero
li $t5, 8
main.cycle:
beq $t3, $t0, continue
second.cycle:
beq $t2, $t0, third.cycle
la $a0, element
li $v0, 4
syscall
move $a0, $t3
li $v0, 1
syscall
la $a0, comma
li $v0, 4
syscall
move $a0, $t2
li $v0, 1
syscall
li $v0, 7
syscall
sdc1 $f0, 0($a1)
add $a1, $a1, $t5
la $a0, enter
li $v0, 4
syscall
addi $t2, $t2, 1 #faz j++
j second.cycle
third.cycle:
addi $t3, $t3, 1
move $t2, $zero
j main.cycle
continue:
jr $ra
buildID:
move $t2,$zero #i=0
move $t3,$zero #j=0
first.loop:
beq $t2,$a2,continue
second.loop:
beq $t3,$a2,controle.conts
bne $t2,$t3,element.zero
sdc1 $f28,0($a1)
end.second.loop:
add $a1,$a1,$t5
addi $t3,$t3,1
j second.loop
element.zero:
sdc1 $f30,0($a1)
j end.second.loop
controle.conts:
addi $t2,$t2,1
move $t3,$zero
j first.loop
copia_matriz:
move $t0,$0
move $t1,$0
loop:
beq $t0,$a1,fim_copia_matriz
beq $t1,$a1,incrementa.zera
ldc1 $f1,0($a0)
sdc1 $f1,0($a2)
addi $a0,$a0,8
addi $a2,$a2,8
addi $t1,$t1,1
j loop
incrementa.zera:
addi $t0,$t0,1
move $t1,$0
j loop
fim_copia_matriz:
jr $ra
printmatrix:
move $t0,$a2
move $t1,$a2
move $t2, $zero #reset i
move $t3, $zero #reset j
main.cycle3: #main cycle that print the matrix (first for)
beq $t2, $a2, exit3 #if i equal the number of lines of the matrix jump to exit3
la $a0, bar #load the addr of barleft into $a0
li $v0, 4 #4 is the print_string syscall
syscall #do the syscall
second.cycle3: #second cycle that print the matrix (second for)
la $a0, tab #load the addr of tab into $a0
li $v0, 4 #4 is the print_string syscall
syscall
beq $t3, $t0, third.cycle3 #if j equal the number of columms of the matrix go to the third cycle
mul $t4, $t0, $t2 #ColC*i
add $t4, $t4, $t3 #ColC*i+j
sll $t4, $t4, 3 #(ColC*i+j)*8
add $t5, $a1, $t4 #go to the element C[i][j]
ldc1 $f12, 0($t5)
li $v0, 3 #3 is the print_double syscall
syscall #do the syscall
move $t4, $zero #reset the index of the element
move $t5, $zero #reset the adress of the element
addi $t3, $t3, 1 #do j++
j second.cycle3 #continue the while with j++
third.cycle3: #third cycle that builds the matrix
addi $t2, $t2, 1 #do i++
la $a0, bar #load the addr of barright into $a0
li $v0, 4 #4 is the print_string syscall
syscall #do the syscall
la $a0, enter #load the addr of enter into $a0
li $v0, 4 #4 is the print_string syscall
syscall #do the syscall
move $t3, $zero #reset j
j main.cycle3 #continue the while with i++
exit3: #after print the matrix, return to main
la $a0, enter #load the addr of enter into $a0
li $v0, 4 #4 is the print_string syscall
syscall #do the syscall
jr $ra #return to main
I don't know how to apply the Gauss method . can you guys help me?
See if it helps. cheers