-
Notifications
You must be signed in to change notification settings - Fork 0
/
campo.asm
479 lines (467 loc) · 11.3 KB
/
campo.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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
.data
.LC2:
.asciz "SITUACAO DO CAMPO MINADO"
.LC3:
.ascii " 8 "
.LC4:
.ascii "%d "
.LC5:
.string " %d "
.LC6:
.string ""
.LC0:
.word 0, 9, 9, 9, 0, 9, 0, 9
.word 0, 0, 0, 0, 0, 0, 9, 9
.word 0, 0, 9, 9, 0, 0, 0, 0
.word 0, 0, 0, 0, 0, 0, 0, 9
.word 0, 9, 0, 9, 9, 0, 9, 0
.word 0, 9, 0, 0, 0, 9, 9, 9
.word 0, 0, 9, 0, 0, 0, 0, 0
.word 9, 0, 0, 9, 0, 9, 0, 9
.LC1:
.word -1, -1, -1, -1, -1, -1, -1, -1
.word -1, -1, -1, -1, -1, -1, -1, -1
.word -1, -1, -1, -1, -1, -1, -1, -1
.word -1, -1, -1, -1, -1, -1, -1, -1
.word -1, -1, -1, -1, -1, -1, -1, -1
.word -1, -1, -1, -1, -1, -1, -1, -1
.word -1, -1, -1, -1, -1, -1, -1, -1
.word -1, -1, -1, -1, -1, -1, -1, -1
.text
mostra_campo:
addi sp,sp,-48
sw ra,44(sp)
sw s0,40(sp)
addi s0,sp,48
sw a0,-36(s0)
sw a1,-40(s0)
sw a2,-44(s0)
sw a3,-48(s0)
lui a5,%hi(.LC2)
addi a0,a5,%lo(.LC2)
#ecall puts
sw zero,-20(s0)
j .L2
.L8:
sw zero,-24(s0)
j .L3
.L7:
lw a4,-48(s0)
li a5,1
bne a4,a5,.L4
lw a5,-20(s0)
slli a5,a5,5
lw a4,-36(s0)
add a4,a4,a5
lw a5,-24(s0)
slli a5,a5,2
add a5,a4,a5
lw a4,0(a5)
li a5,9
bne a4,a5,.L4
lui a5,%hi(.LC3)
addi a0,a5,%lo(.LC3)
# call printf
j .L5
.L4:
lw a5,-20(s0)
slli a5,a5,5
lw a4,-40(s0)
add a4,a4,a5
lw a5,-24(s0)
slli a5,a5,2
add a5,a4,a5
lw a4,0(a5)
li a5,-1
bne a4,a5,.L6
lw a5,-20(s0)
slli a5,a5,5
lw a4,-40(s0)
add a4,a4,a5
lw a5,-24(s0)
slli a5,a5,2
add a5,a4,a5
lw a5,0(a5)
mv a1,a5
lui a5,%hi(.LC4)
addi a0,a5,%lo(.LC4)
#call printf
j .L5
.L6:
lw a5,-20(s0)
slli a5,a5,5
lw a4,-40(s0)
add a4,a4,a5
lw a5,-24(s0)
slli a5,a5,2
add a5,a4,a5
lw a5,0(a5)
mv a1,a5
lui a5,%hi(.LC5)
addi a0,a5,%lo(.LC5)
#call printf
.L5:
lw a5,-24(s0)
addi a5,a5,1
sw a5,-24(s0)
.L3:
lw a4,-24(s0)
lw a5,-44(s0)
blt a4,a5,.L7
lui a5,%hi(.LC6)
addi a0,a5,%lo(.LC6)
#call puts
lw a5,-20(s0)
addi a5,a5,1
sw a5,-20(s0)
.L2:
lw a4,-20(s0)
lw a5,-44(s0)
blt a4,a5,.L8
nop
nop
lw ra,44(sp)
lw s0,40(sp)
addi sp,sp,48
jr ra
calcula_bomba:
addi sp,sp,-48
sw s0,44(sp)
addi s0,sp,48
sw a0,-36(s0)
sw a1,-40(s0)
lw a5,-40(s0)
addi a5,a5,-1
sw a5,-32(s0)
sw zero,-20(s0)
j .L10
.L23:
sw zero,-24(s0)
j .L11
.L22:
sw zero,-28(s0)
lw a5,-20(s0)
slli a5,a5,5
lw a4,-36(s0)
add a4,a4,a5
lw a5,-24(s0)
slli a5,a5,2
add a5,a4,a5
lw a4,0(a5)
li a5,8
beq a4,a5,.L24
lw a5,-20(s0)
beq a5,zero,.L14
lw a5,-24(s0)
beq a5,zero,.L14
lw a4,-20(s0)
li a5,134217728
addi a5,a5,-1
add a5,a4,a5
slli a5,a5,5
lw a4,-36(s0)
add a4,a4,a5
lw a5,-24(s0)
addi a5,a5,-1
slli a5,a5,2
add a5,a4,a5
lw a4,0(a5)
li a5,8
bne a4,a5,.L14
lw a5,-28(s0)
addi a5,a5,1
sw a5,-28(s0)
.L14:
lw a5,-20(s0)
beq a5,zero,.L15
lw a4,-20(s0)
li a5,134217728
addi a5,a5,-1
add a5,a4,a5
slli a5,a5,5
lw a4,-36(s0)
add a4,a4,a5
lw a5,-24(s0)
slli a5,a5,2
add a5,a4,a5
lw a4,0(a5)
li a5,8
bne a4,a5,.L15
lw a5,-28(s0)
addi a5,a5,1
sw a5,-28(s0)
.L15:
lw a5,-20(s0)
beq a5,zero,.L16
lw a4,-24(s0)
lw a5,-32(s0)
beq a4,a5,.L16
lw a4,-20(s0)
li a5,134217728
addi a5,a5,-1
add a5,a4,a5
slli a5,a5,5
lw a4,-36(s0)
add a4,a4,a5
lw a5,-24(s0)
addi a5,a5,1
slli a5,a5,2
add a5,a4,a5
lw a4,0(a5)
li a5,8
bne a4,a5,.L16
lw a5,-28(s0)
addi a5,a5,1
sw a5,-28(s0)
.L16:
lw a5,-24(s0)
beq a5,zero,.L17
lw a5,-20(s0)
slli a5,a5,5
lw a4,-36(s0)
add a4,a4,a5
lw a5,-24(s0)
addi a5,a5,-1
slli a5,a5,2
add a5,a4,a5
lw a4,0(a5)
li a5,8
bne a4,a5,.L17
lw a5,-28(s0)
addi a5,a5,1
sw a5,-28(s0)
.L17:
lw a4,-24(s0)
lw a5,-32(s0)
beq a4,a5,.L18
lw a5,-20(s0)
slli a5,a5,5
lw a4,-36(s0)
add a4,a4,a5
lw a5,-24(s0)
addi a5,a5,1
slli a5,a5,2
add a5,a4,a5
lw a4,0(a5)
li a5,8
bne a4,a5,.L18
lw a5,-28(s0)
addi a5,a5,1
sw a5,-28(s0)
.L18:
lw a4,-20(s0)
lw a5,-32(s0)
beq a4,a5,.L19
lw a5,-24(s0)
beq a5,zero,.L19
lw a5,-20(s0)
addi a5,a5,1
slli a5,a5,5
lw a4,-36(s0)
add a4,a4,a5
lw a5,-24(s0)
addi a5,a5,-1
slli a5,a5,2
add a5,a4,a5
lw a4,0(a5)
li a5,8
bne a4,a5,.L19
lw a5,-28(s0)
addi a5,a5,1
sw a5,-28(s0)
.L19:
lw a4,-20(s0)
lw a5,-32(s0)
beq a4,a5,.L20
lw a5,-20(s0)
addi a5,a5,1
slli a5,a5,5
lw a4,-36(s0)
add a4,a4,a5
lw a5,-24(s0)
slli a5,a5,2
add a5,a4,a5
lw a4,0(a5)
li a5,8
bne a4,a5,.L20
lw a5,-28(s0)
addi a5,a5,1
sw a5,-28(s0)
.L20:
lw a4,-20(s0)
lw a5,-32(s0)
beq a4,a5,.L21
lw a4,-24(s0)
lw a5,-32(s0)
beq a4,a5,.L21
lw a5,-20(s0)
addi a5,a5,1
slli a5,a5,5
lw a4,-36(s0)
add a4,a4,a5
lw a5,-24(s0)
addi a5,a5,1
slli a5,a5,2
add a5,a4,a5
lw a4,0(a5)
li a5,8
bne a4,a5,.L21
lw a5,-28(s0)
addi a5,a5,1
sw a5,-28(s0)
.L21:
lw a5,-20(s0)
slli a5,a5,5
lw a4,-36(s0)
add a4,a4,a5
lw a5,-24(s0)
slli a5,a5,2
add a5,a4,a5
lw a4,-28(s0)
sw a4,0(a5)
j .L13
.L24:
nop
.L13:
lw a5,-24(s0)
addi a5,a5,1
sw a5,-24(s0)
.L11:
lw a4,-24(s0)
lw a5,-40(s0)
blt a4,a5,.L22
lw a5,-20(s0)
addi a5,a5,1
sw a5,-20(s0)
.L10:
lw a4,-20(s0)
lw a5,-40(s0)
blt a4,a5,.L23
nop
nop
lw s0,44(sp)
addi sp,sp,48
jr ra
#.LC7:
# .string "\nDigite as coordenadas do campo minado (coluna)(linha): "
#.LC8:
# .string "%d"
#.LC9:
# .string "\nA BOMBA EXPLODIU! VOCE PERDEU!"
main:
addi sp,sp,-544
sw ra,540(sp)
sw s0,536(sp)
addi s0,sp,544
lui a5,%hi(.LC0)
addi a4,a5,%lo(.LC0)
addi a5,s0,-280
mv a3,a4
li a4,256
mv a2,a4
mv a1,a3
mv a0,a5
#call memcpy
lui a5,%hi(.LC1)
addi a4,a5,%lo(.LC1)
addi a5,s0,-536
mv a3,a4
li a4,256
mv a2,a4
mv a1,a3
mv a0,a5
# call memcpy
li a5,8
sw a5,-20(s0)
sw zero,-24(s0)
addi a5,s0,-280
lw a1,-20(s0)
mv a0,a5
call calcula_bomba
.L30:
addi a4,s0,-536
addi a5,s0,-280
lw a3,-24(s0)
lw a2,-20(s0)
mv a1,a4
mv a0,a5
call mostra_campo
#lui a5,%hi(.LC7)
#addi a0,a5,%lo(.LC7)
#call puts
addi a5,s0,-544
mv a1,a5
# lui a5,%hi(.LC8)
#addi a0,a5,%lo(.LC8)
#call scanf
addi a5,s0,-540
mv a1,a5
#lui a5,%hi(.LC8)
#addi a0,a5,%lo(.LC8)
#call scanf
lui a5,%hi(.LC6)
addi a0,a5,%lo(.LC6)
#call puts
lw a5,-544(s0)
lw a4,-20(s0)
blt a4,a5,.L33
lw a5,-540(s0)
lw a4,-20(s0)
blt a4,a5,.L33
lw a5,-540(s0)
beq a5,zero,.L33
lw a5,-544(s0)
beq a5,zero,.L33
lw a5,-540(s0)
addi a5,a5,-1
sw a5,-540(s0)
lw a5,-544(s0)
addi a5,a5,-1
sw a5,-544(s0)
lw a4,-540(s0)
lw a5,-544(s0)
lw a2,-540(s0)
lw a3,-544(s0)
slli a4,a4,3
add a5,a4,a5
slli a5,a5,2
addi a4,s0,-16
add a5,a4,a5
lw a4,-264(a5)
slli a5,a2,3
add a5,a5,a3
slli a5,a5,2
addi a3,s0,-16
add a5,a3,a5
sw a4,-520(a5)
lw a4,-540(s0)
lw a5,-544(s0)
slli a4,a4,3
add a5,a4,a5
slli a5,a5,2
addi a4,s0,-16
add a5,a4,a5
lw a4,-264(a5)
li a5,8
bne a4,a5,.L30
li a5,1
sw a5,-24(s0)
#call puts
addi a4,s0,-536
addi a5,s0,-280
lw a3,-24(s0)
lw a2,-20(s0)
mv a1,a4
mv a0,a5
call mostra_campo
j .L32
.L33:
nop
j .L30
.L32:
li a5,0
mv a0,a5
lw ra,540(sp)
lw s0,536(sp)
addi sp,sp,544
jr ra