2
I have some questions about an academic paper in which the teacher asks to list, delete, insert and select matrices.
If someone could explain to me how to do thank you, follows down the slides of the work and what is requested, the part of the matrices is already done but I don’t even know how to do data management. In red is the theme on which I have doubts
.data
prompt: .asciiz "Digite o nº de linhas para a matriz1 :"
prompt2: .asciiz "Digite o nº de colunas para a matriz1 :"
prompt3: .asciiz "Digite o nº de colunas para a matriz2 :"
print1: .asciiz "Insira os valores da matriz1 : "
print2: .asciiz "Insira os valores da matriz2 : "
print7: .asciiz "\t"
print8: .asciiz "\n"
menu: .asciiz "1-Multiplicação\n2-Adicão\n3-Subtração\n"
menu2: .asciiz "1-Ler\n2-Adicionar\n3-Selecionar\n4-Apagar"
opcao: .asciiz "\nEscolha a opção : "
toWrite: .asciiz "Hello World was here"
fileName: .asciiz "C:/Users/DimiHk/Downloads/trabalho.txt"
fileWords: .space 1024
.text
.globl main
main:
la $a0, print8
li $v0, 4
syscall
addi $v0, $0, 4
la $a0,menu2
syscall
addi $v0, $0, 4
la $a0,opcao
syscall
addi $v0, $0, 5
syscall
add $t3, $0, $v0
beq $t3, 1, ler
beq $t3, 2, adicionar
beq $t3, 3, selecionar
beq $t3, 4, apagar
syscall
ler:
li $v0,13
la $a0,fileName
li $a1,0
syscall
move $s0,$v0
li $v0, 14
move $a0,$s0
la $a1,fileWords
la $a2,1024
syscall
li $v0, 4
la $a0,fileWords
syscall
li $v0, 16
move $a0,$s0
syscall
j main
adicionar:
la $a0, print8
li $v0, 4
syscall
la $a0, prompt
li $v0, 4
syscall
li $v0, 5
syscall
move $t0, $v0
la $a0, prompt2
li $v0, 4
syscall
li $v0, 5
syscall
move $t1, $v0
la $a0, prompt3
li $v0, 4
syscall
li $v0, 5
syscall
move $t2, $v0
li $v0, 4
la $a0, print1
syscall
li $v0, 1
li $v0, 4
la $a0, print8
syscall
li $t3, 0
mul $t4, $t0, $t1
mul $s5, $t1, $t2
mul $t8, $t4, 4
j alocacao_matriz1
alocacao_matriz1:
move $a0, $t8
li $v0, 9
syscall
move $s0, $v0
move $t6, $s0
j armazena_matriz1
armazena_matriz1:
beq $t3, $t4, inicializa_matriz2
li $v0, 5
syscall
move $t5, $v0
sw $t5, 0($s0)
addi $s0, $s0, 4
addi $t3, $t3, 1
j armazena_matriz1
inicializa_matriz2:
li $v0, 4
la $a0, print2
syscall
li $v0, 4
la $a0, print8
syscall
move $a0, $t8
li $v0, 9
syscall
move $s1, $v0
move $t7, $s1
move $t3, $zero
j armazena_matriz2
armazena_matriz2:
beq $t3, $s5, menus
li $v0, 5
syscall
move $t5, $v0
sw $t5, 0($s1)
addi $s1, $s1, 4
addi $t3, $t3, 1
j armazena_matriz2
selecionar:
apagar:
menus:
la $a0, print8
li $v0, 4
syscall
addi $v0, $0, 4
la $a0,menu
syscall
addi $v0, $0, 4
la $a0,opcao
syscall
addi $v0, $0, 5
syscall
add $t3, $0, $v0
beq $t3, 1, multiplicacao
beq $t3, 2, adicao
beq $t3, 3, subtracao
syscall
multiplicacao:
li $t3, 0
li $s4, 0
li $s5, 0
li $s7, 0
mul $t4, $t0, $t2
move $s0, $t6
move $s1, $t7
move $t0, $t7
mul $s6, $t1, 4
mul $t8, $t2, 4
la $a0, print8
li $v0, 4
syscall
j matrix_load
matrix_load:
beq $t3, $t1, print_and_reset
lw $t5, 0($s0)
addi $s0, $s0, 4
lw $t9, 0($s1)
add $s1, $s1, $t8
mul $s3, $t5, $t9
add $s4, $s4, $s3
addi $t3, $t3, 1
j matrix_load
print_and_reset:
move $a0, $s4
li $v0, 1
syscall
la $a0, print7
li $v0, 4
syscall
move $s0, $t6
addi $t0, $t0, 4
move $s1, $t0
addi $s5, $s5, 1
addi $s7, $s7, 1
li $t3, 0
li $s4, 0
beq $s5, $t4, main
beq $s7, $t2, mat1_next_row
j matrix_load
mat1_next_row:
add $t6, $t6, $s6
move $s0, $t6
move $s1, $t7
move $t0, $t7
li $s7, 0
la $a0, print8
li $v0, 4
syscall
j matrix_load
adicao:
bne $t0,$t2,main
li $t3, 0
li $s4, 0
li $s5, 0
li $s7, 0
mul $t4, $t0, $t2
move $s0, $t6
move $s1, $t7
la $a0, print8
li $v0, 4
syscall
j adicao_matriz
adicao_matriz:
beq $t3,$t1,reseta_valores
lw $s3,0($s0)
lw $s4,0($s1)
add $s6,$s3,$s4
move $a0, $s6
li $v0, 1
syscall
la $a0, print7
li $v0, 4
syscall
addi $s0,$s0,4
addi $s1,$s1,4
addi $t3,$t3,1
addi $s5,$s5,1
j adicao_matriz
reseta_valores:
beq $s5,$t4,main
la $a0, print8
li $v0, 4
syscall
li $t3,0
j adicao_matriz
subtracao:
bne $t0,$t2,main
li $t3, 0
li $s4, 0
li $s5, 0
li $s7, 0
mul $t4, $t0, $t2
move $s0, $t6
move $s1, $t7
la $a0, print8
li $v0, 4
syscall
j sub_matriz
sub_matriz:
beq $t3,$t1,reseta_sub
lw $s3,0($s0)
lw $s4,0($s1)
sub $s6,$s3,$s4
move $a0, $s6
li $v0, 1
syscall
la $a0, print7
li $v0, 4
syscall
addi $s0,$s0,4
addi $s1,$s1,4
addi $t3,$t3,1
addi $s5,$s5,1
j sub_matriz
reseta_sub:
beq $s5,$t4,main
la $a0, print8
li $v0, 4
syscall
li $t3,0
j sub_matriz