-
Notifications
You must be signed in to change notification settings - Fork 0
/
vestibular.spim
71 lines (57 loc) · 1.22 KB
/
vestibular.spim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
.data
novaLinha: .asciiz "\n"
vestibular: .space 10001
resposta: .space 10001
.text
# Index
# t0 = numero de questoes
# t1 = Acertos
# t2 = aux para percorrer vetor de comparacao
# t3 = str vestibular
# t4 = str resposta
main:
# Le o numero de questoes do vestibular
li $v0, 5
syscall
move $t0, $v0
# Le a primeira string
li $v0, 8
la $a0, vestibular
li $a1, 10000
syscall
# le a segunda string
li $v0, 8
la $a0, resposta
li $a1, 10000
syscall
addi $t1, $zero, 0
addi $t2, $zero, 0
la $t3, vestibular
la $t4, resposta
j while
while:
bgt $t2, $t0, exit # Encerra o programa ao verificar o vetor inteiro
lb $t5, 0($t3)
lb $t6, 0($t4)
addi $t2, $t2, 1
addi $t3, $t3, 1
addi $t4, $t4, 1
sub $t7, $t5, $t6 # Verifica igualdade, caso seja igual acertos++
beq $t7, $zero, acerto
j while # Recursao
acerto:
addi $t1, $t1, 1
j while
exit:
# Imprime numero de acertos
sub $t1, $t1, 1
li $v0, 1
move $a0, $t1
syscall
# Quebra de linha
li $v0, 4
la $a0, novaLinha
syscall
# Fim do programa
li $v0, 10
syscall