-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path32)STACK 23 09 17
206 lines (142 loc) · 5.68 KB
/
32)STACK 23 09 17
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
.data
msg1:.asciiz "Dammi il valore di arr["
msg2:.asciiz "]["
msg3:.asciiz "] : "
msg_spazio:.asciiz " "
msg_slash:.asciiz "\n"
msg4:.asciiz "\nMatrice Originale\n"
msg5:.asciiz "\nMatrice Nuova Rispetto ala 1^ colonna\n"
.text
.globl main
main:
addi $sp,$sp,-36
la $a0,0($sp)
jal riempi_array
li $v0,4
la $a0,msg4
syscall
la $a0,0($sp)
jal stampa_array
li $v0,4
la $a0,msg5
syscall
la $a0,0($sp)
jal nuova_array
la $a0,0($sp)
jal stampa_array
li $v0,10
syscall
##############################################################
riempi_array:
move $t0,$a0
li $t1,0 #i
li $t2,0 #j
loop1:
beq $t2,3,incrementa_i
li $v0,4
la $a0,msg1
syscall
li $v0,1
move $a0,$t1
syscall
li $v0,4
la $a0,msg2
syscall
li $v0,1
move $a0,$t2
syscall
li $v0,4
la $a0,msg3
syscall
li $v0,5
syscall
sw $v0,0($t0)
addi $t0,$t0,4
addi $t2,$t2,1
j loop1
incrementa_i:
addi $t1,$t1,1
beq $t1,3,exit1
li $t2,0
j loop1
exit1 :
jr $ra
##############################################################
stampa_array:
move $t0,$a0
li $t1,0 # i
li $t2,0 # j
loop2:
beq $t2,3,scendi_indice
lw $t3,0($t0)
move $a0,$t3
li $v0,1
syscall
li $v0,4
la $a0,msg_spazio
syscall
addi $t0,$t0,4
addi $t2,$t2,1
j loop2
scendi_indice:
li $v0,4
la $a0,msg_slash
syscall
li $t2,0
addi $t1,$t1,1
beq $t1,3,exit2
j loop2
exit2:
jr $ra
##############################################################
nuova_array:
move $t0,$a0
li $t1,0
loop3:
lw $t3,0($t0)
lw $t4,12($t0)
lw $t5,24($t0)
blt $t4,$t3,swap_first_second
blt $t5,$t4,swap_second_third
blt $t5,$t3,swap_third_first
j esci3
swap_first_second:
sw $t4,0($t0)
sw $t3,12($t0)
lw $t3,4($t0)
lw $t4,16($t0)
sw $t4,4($t0)
sw $t3,16($t0)
lw $t3,8($t0)
lw $t4,20($t0)
sw $t4,8($t0)
sw $t3,20($t0)
j esci_confronto
swap_second_third:
sw $t5,12($t0)
sw $t4,24($t0)
lw $t4,16($t0)
lw $t5,28($t0)
sw $t5,16($t0)
sw $t4,28($t0)
lw $t4,20($t0)
lw $t5,32($t0)
sw $t5,20($t0)
sw $t4,32($t0)
j esci_confronto
swap_third_first:
sw $t3,24($t0)
sw $t5,0($t0)
lw $t5,28($t0)
lw $t3,4($t0)
sw $t3,28($t0)
sw $t5,4($t0)
lw $t5,32($t0)
lw $t3,8($t0)
sw $t3,32($t0)
sw $t5,8($t0)
esci_confronto:
li $t1,0
j loop3
esci3:
jr $ra