-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sentencia_for_en_MIPS.asm
72 lines (48 loc) · 1.33 KB
/
Sentencia_for_en_MIPS.asm
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
72
#Funcionamiento del codigo:
# int main() {
# int contador = 0; // Contador
# int numero_repeticiones = 9; // Número de repeticiones
# int suma = 0; // Resultado de la suma
# for (contador = 0; contador != numero_repeticiones; contador++) {
# printf("\nIntroduce un numero: ");
# int numero;
# scanf("%d", &numero);
# suma += numero;
# }
# printf("\nFor terminado.");
# printf("\nLa suma de todos los numeros introducidos es: %d", suma);
# return 0;
# }
.data
mensaje1: .asciiz "\nIntroduce un numero: "
mensaje2: .asciiz "\nFor terminado."
mensaje3: .asciiz "\nLa suma de todos los numeros introducidos es: "
.text
li $t0, 0 # Contador
li $t1, 9 # Numero de repeticiones
li $t4, 0 #Resultado suma
for_comprobacion:
bne $t0, $t1, for # Saltar a 'for_continue' si $t0 no es igual a $t1
j fin
for:
li $v0, 4
la $a0, mensaje1
syscall
li $v0, 5
syscall
move $t3, $v0
add $t4,$t4,$t3
addi $t0, $t0, 1
j for_comprobacion
fin:
li $v0, 4
la $a0, mensaje2
syscall
li $v0, 4
la $a0, mensaje3
syscall
li $v0, 1 # '1' Sirve para imprimir un entero
move $a0, $t4
syscall
li $v0, 10
syscall