Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- vetA: .space 32
- vetB: .space 32
- vetC: .space 32
- input: .asciiz "Entre com o tamanho dos vetores (máx. = 8): "
- inputA: .asciiz "Entre com os valores do vetor A:\n"
- inputB: .asciiz "Entre com os valores do vetor B:\n"
- showC: .asciiz "Exibindo o vetor C:"
- err: .asciiz "Valor inválido"
- vetAtxt:.asciiz "Vetor A["
- vetBtxt:.asciiz "Vetor B["
- vetCtxt:.asciiz "\nVetor C["
- vetFim: .asciiz "]: "
- .text
- main:
- li $t0, 0 # Contador
- li $t1, 0 # Contador Auxiliar 1
- li $t2, 0 # Contador Auxiliar 2
- li $t3, 0 # Contador Auxiliar 3
- li $t4, 0 # Auxiliar
- li $t5, 0 # Auxiliar 2
- li $s0, 8 # Máx elementos vetor/Máx valor
- li $s1, 1 # Mín elementos vetor/Mín valor
- la $s2, vetA # Endereço inicial vet A
- la $s3, vetB # Endereço inicial vet B
- la $s4, vetC # Endereço inicial vet C
- li $s5, 0 # Tam Vet
- tamVet:
- li $v0, 4
- la $a0, input
- syscall
- li $v0, 5
- syscall
- blt $v0, $s1, erroTamVet
- bgt $v0, $s0, erroTamVet
- add $s5, $0, $v0
- jal preencherVetA
- jal preencherVetB
- jal preencherVetC
- jal exibirVetC
- li $v0, 10
- syscall
- erroTamVet:
- li $v0, 4
- la $a0, err
- syscall
- j tamVet
- preencherVetA:
- li $t0, 0
- add $t1, $0, $s2
- li $v0, 4
- la $a0, inputA
- syscall
- ini_loopVetA:
- beq $t0, $s5, fim_loopVetA
- li $v0, 4
- la $a0, vetAtxt
- syscall
- li $v0, 1
- add $a0, $0, $t0
- syscall
- li $v0, 4
- la $a0, vetFim
- syscall
- li $v0, 5
- syscall
- sw $v0, ($t1)
- add $t0, $t0, 1
- add $t1, $t1, 4
- j ini_loopVetA
- fim_loopVetA:
- jr $ra
- preencherVetB:
- li $t0, 0
- add $t1, $0, $s3
- li $v0, 4
- la $a0, inputB
- syscall
- ini_loopVetB:
- beq $t0, $s5, fim_loopVetB
- li $v0, 4
- la $a0, vetBtxt
- syscall
- li $v0, 1
- add $a0, $0, $t0
- syscall
- li $v0, 4
- la $a0, vetFim
- syscall
- li $v0, 5
- syscall
- sw $v0, ($t1)
- add $t0, $t0, 1
- add $t1, $t1, 4
- j ini_loopVetB
- fim_loopVetB:
- jr $ra
- preencherVetC:
- li $t0, 0
- add $t1, $0, $s2
- add $t2, $0, $s3
- add $t3, $0, $s4
- ini_loopVetC1:
- beq $t0, $s5, fim_loopVetC1
- lw $t5, 0($t1)
- add $t4, $0, $t5
- lw $t5, 0($t2)
- add $t4, $t4, $t5
- srl $t4, $t4, 1
- sw $t4, ($t3)
- add $t0, $t0, 1
- add $t1, $t1, 4
- add $t2, $t2, 4
- add $t3, $t3, 4
- j ini_loopVetC1
- fim_loopVetC1:
- jr $ra
- exibirVetC:
- li $t0, 0
- add $t1, $0, $s4
- li $v0, 4
- la $a0, showC
- syscall
- ini_loopVetC2:
- beq $t0, $s5, fim_loopVetC2
- li $v0, 4
- la $a0, vetCtxt
- syscall
- li $v0, 1
- add $a0, $0, $t0
- syscall
- li $v0, 4
- la $a0, vetFim
- syscall
- li $v0, 1
- lw $a0, 0($t1)
- syscall
- add $t0, $t0, 1
- add $t1, $t1, 4
- j ini_loopVetC2
- fim_loopVetC2:
- jr $ra
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement