-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path26)Traccia 04 2012
92 lines (67 loc) · 1.93 KB
/
26)Traccia 04 2012
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
.data
msg1:.asciiz "Inizializzo l'array... fatto!"
msg2:.asciiz"\n\nNumero dell' elemento (0-19, -1 per terminare) :"
msg3:.asciiz "L'elemento di posto "
msg4:.asciiz " vale -> "
.align 2
array :.space 80
.text
.globl main
main:
la $a0,array
li $t1,0
loop1:
beq $t1,20,jump_to_continue
sll $t2,$t1,2
sll $t3,$t1,1
add $t4,$t3,$t2
add $t4,$t4,1
sw $t4,0($a0)
addi $a0,$a0,4
addi $t1,$t1,1
j loop1
jump_to_continue:
li $v0,4
la $a0,msg1
syscall
loop2:
li $v0,4
la $a0,msg2
syscall
li $v0,5
syscall
beq $v0,-1,exit
move $s0,$v0
li $v0,4
la $a0,msg3
syscall
li $v0,1
move $a0,$s0
syscall
li $v0,4
la $a0,msg4
syscall
move $a1,$s0
la $a0,array
jal array_element
move $a0,$v0
li $v0,1
syscall
j loop2
exit:
li $v0,10
syscall
##########################################################
array_element :
move $t0,$a0
move $t1,$a1
li $t2,0
loop3:
beq $t2,$t1,found
addi $t0,$t0,4
addi $t2,$t2,1
j loop3
found:
lw $t3,0($t0)
move $v0,$t3
jr $ra