-
Notifications
You must be signed in to change notification settings - Fork 1
/
spimbot.s
1902 lines (1803 loc) · 42.1 KB
/
spimbot.s
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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.data
# syscall constants
PRINT_STRING = 4
PRINT_CHAR = 11
PRINT_INT = 1
# memory-mapped I/O
VELOCITY = 0xffff0010
ANGLE = 0xffff0014
ANGLE_CONTROL = 0xffff0018
BOT_X = 0xffff0020
BOT_Y = 0xffff0024
TIMER = 0xffff001c
SUBMIT_ORDER = 0xffff00b0
DROPOFF = 0xffff00c0
PICKUP = 0xffff00e0
GET_TILE_INFO = 0xffff0050
SET_TILE = 0xffff0058
REQUEST_PUZZLE = 0xffff00d0
SUBMIT_SOLUTION = 0xffff00d4
BONK_INT_MASK = 0x1000
BONK_ACK = 0xffff0060
TIMER_INT_MASK = 0x8000
TIMER_ACK = 0xffff006c
REQUEST_PUZZLE_INT_MASK = 0x800
REQUEST_PUZZLE_ACK = 0xffff00d8
GET_MONEY = 0xffff00e4
GET_LAYOUT = 0xffff00ec
SET_REQUEST = 0xffff00f0
GET_REQUEST = 0xffff00f4
GET_INVENTORY = 0xffff0040
GET_TURNIN_ORDER = 0xffff0044
GET_TURNIN_USERS = 0xffff0048
GET_SHARED = 0xffff004c
GET_BOOST = 0xffff0070
GET_INGREDIENT_INSTANT = 0xffff0074
FINISH_APPLIANCE_INSTANT = 0xffff0078
MAX_ITERATION = 6
MAX_TIME = 9250000
bitboard_jump:
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 6 2 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 5 3 0 0
.byte 5 3 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 6 2 0 0
.byte 4 4 0 0
.byte 4 4 0 0
.byte 4 4 0 0
.byte 4 4 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 6 2 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 5 3 0 0
.byte 5 3 0 0
.byte 3 5 0 0
.byte 3 5 0 0
.byte 3 5 0 0
.byte 3 3 2 0
.byte 3 5 0 0
.byte 3 5 0 0
.byte 3 5 0 0
.byte 3 5 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 6 2 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 5 3 0 0
.byte 5 3 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 6 2 0 0
.byte 4 4 0 0
.byte 4 4 0 0
.byte 4 4 0 0
.byte 4 4 0 0
.byte 2 6 0 0
.byte 2 6 0 0
.byte 2 6 0 0
.byte 2 4 2 0
.byte 2 6 0 0
.byte 2 6 0 0
.byte 2 3 3 0
.byte 2 3 3 0
.byte 2 6 0 0
.byte 2 6 0 0
.byte 2 6 0 0
.byte 2 4 2 0
.byte 2 6 0 0
.byte 2 6 0 0
.byte 2 6 0 0
.byte 2 6 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 6 2 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 5 3 0 0
.byte 5 3 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 6 2 0 0
.byte 4 4 0 0
.byte 4 4 0 0
.byte 4 4 0 0
.byte 4 4 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 6 2 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 5 3 0 0
.byte 5 3 0 0
.byte 3 5 0 0
.byte 3 5 0 0
.byte 3 5 0 0
.byte 3 3 2 0
.byte 3 5 0 0
.byte 3 5 0 0
.byte 3 5 0 0
.byte 3 5 0 0
.byte 1 7 0 0
.byte 1 7 0 0
.byte 1 7 0 0
.byte 1 5 2 0
.byte 1 7 0 0
.byte 1 7 0 0
.byte 1 4 3 0
.byte 1 4 3 0
.byte 1 7 0 0
.byte 1 7 0 0
.byte 1 7 0 0
.byte 1 5 2 0
.byte 1 3 4 0
.byte 1 3 4 0
.byte 1 3 4 0
.byte 1 3 4 0
.byte 1 7 0 0
.byte 1 7 0 0
.byte 1 7 0 0
.byte 1 5 2 0
.byte 1 7 0 0
.byte 1 7 0 0
.byte 1 4 3 0
.byte 1 4 3 0
.byte 1 7 0 0
.byte 1 7 0 0
.byte 1 7 0 0
.byte 1 5 2 0
.byte 1 7 0 0
.byte 1 7 0 0
.byte 1 7 0 0
.byte 1 7 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 6 2 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 5 3 0 0
.byte 5 3 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 6 2 0 0
.byte 4 4 0 0
.byte 4 4 0 0
.byte 4 4 0 0
.byte 4 4 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 6 2 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 5 3 0 0
.byte 5 3 0 0
.byte 3 5 0 0
.byte 3 5 0 0
.byte 3 5 0 0
.byte 3 3 2 0
.byte 3 5 0 0
.byte 3 5 0 0
.byte 3 5 0 0
.byte 3 5 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 6 2 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 5 3 0 0
.byte 5 3 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 6 2 0 0
.byte 4 4 0 0
.byte 4 4 0 0
.byte 4 4 0 0
.byte 4 4 0 0
.byte 2 6 0 0
.byte 2 6 0 0
.byte 2 6 0 0
.byte 2 4 2 0
.byte 2 6 0 0
.byte 2 6 0 0
.byte 2 3 3 0
.byte 2 3 3 0
.byte 2 6 0 0
.byte 2 6 0 0
.byte 2 6 0 0
.byte 2 4 2 0
.byte 2 6 0 0
.byte 2 6 0 0
.byte 2 6 0 0
.byte 2 6 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 6 2 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 5 3 0 0
.byte 5 3 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 6 2 0 0
.byte 4 4 0 0
.byte 4 4 0 0
.byte 4 4 0 0
.byte 4 4 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 6 2 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 5 3 0 0
.byte 5 3 0 0
.byte 3 5 0 0
.byte 3 5 0 0
.byte 3 5 0 0
.byte 3 3 2 0
.byte 3 5 0 0
.byte 3 5 0 0
.byte 3 5 0 0
.byte 3 5 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 6 2 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 5 3 0 0
.byte 5 3 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 6 2 0 0
.byte 4 4 0 0
.byte 4 4 0 0
.byte 4 4 0 0
.byte 4 4 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 6 2 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 5 3 0 0
.byte 5 3 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 6 2 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
.byte 8 0 0 0
puzzle: .word 0:452
appliance0: .byte 0
appliance1: .byte 0
layout: .byte 0:225
shared: .word 0:2
order: .word 0:6
score: .word 0:2
request: .word 0:2
stage: .word 0
bins: .byte 0:3
.text
j main
get_appliance:
la $t0 layout
la $t3 bins
sw $t0 GET_LAYOUT
lw $t1 BOT_X
bgt $t1 150 get_appliance_right
lb $t1 32($t0)
la $t2 appliance1
sb $t1 0($t2)
lb $t1 35($t0)
la $t2 appliance0
sb $t1 0($t2)
lb $t1 45($t0)
sb $t1 0($t3)
lb $t1 105($t0)
sb $t1 1($t3)
lb $t1 165($t0)
sb $t1 2($t3)
jr $ra
get_appliance_right:
lb $t1 39($t0)
la $t2 appliance0
sb $t1 0($t2)
lb $t1 42($t0)
la $t2 appliance1
sb $t1 0($t2)
lb $t1 59($t0)
sb $t1 0($t3)
lb $t1 119($t0)
sb $t1 1($t3)
lb $t1 179($t0)
sb $t1 2($t3)
jr $ra
main:
# Construct interrupt mask
li $t4, 0
or $t4, $t4, BONK_INT_MASK # request bonk
or $t4, $t4, TIMER_INT_MASK # timer interrupt bit
or $t4, $t4, REQUEST_PUZZLE_INT_MASK # puzzle interrupt bit
or $t4, $t4, 1 # global enable
mtc0 $t4, $12
#Fill in your code here
la $t1 request
li $t0 1764173471
sw $t0 4($t1)
li $t0 35636716367
sw $t0 0($t1)
sw $t1 SET_REQUEST
########initial stage##########
la $t1 stage
sw $0 0($t1)
lw $t0, BOT_X
blt $t0, 150, run_left
# run_right:
li $t0, 10
sw $t0, VELOCITY
li $t0, 101
sw $t0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
j start
run_left:
li $t0, 10
sw $t0, VELOCITY
li $t0, 79
sw $t0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
start:
jal get_appliance
la $t0, bins
lb $t0, 0($t0)
li $t7, MAX_ITERATION
beq $t0, 7, initial_bread
beq $t0, 11, initial_cheese
beq $t0, 12, initial_onion
j initial_normal
initial_bread:
add $t7, $t7, 2
j initial_normal
initial_cheese:
add $t7, $t7, -2
j initial_normal
initial_onion:
add $t7, $t7, -1
j initial_normal
initial_normal:
# li $t7, MAX_ITERATION ### reserve t7!!!
li $t9, '#' #!!!!!!!warning: don't use t9
li $s7, 0 ### reserve s7!!!
li $s6, 0 ### reserve s6!!!
li $s5, 0 ### RESERVE S5!!!
la $s4, bitboard_jump
la $t0, puzzle
sw $t0, REQUEST_PUZZLE
infinite:
j infinite
.kdata
chunkIH: .space 48
non_intrpt_str: .asciiz "Non-interrupt exception\n"
unhandled_str: .asciiz "Unhandled interrupt type\n"
.ktext 0x80000180
interrupt_handler:
.set noat
move $k1, $at # Save $at
.set at
la $k0, chunkIH
sw $a0, 0($k0) # Get some free registers
sw $v0, 4($k0) # by storing them to a global variable
sw $t0, 8($k0)
sw $t1, 12($k0)
sw $t2, 16($k0)
sw $t3, 20($k0)
sw $t4, 24($k0)
sw $t5, 28($k0)
sw $ra, 32($k0)
sw $a1, 36($k0)
sw $a2, 40($k0)
sw $a3, 44($k0) # can be deleted if not used
###warning: reserve $t0-$t5 for solving puzzle!!!!!!
mfc0 $k0, $13 # Get Cause register
srl $a0, $k0, 2
and $a0, $a0, 0xf # ExcCode field
bne $a0, 0, non_intrpt
interrupt_dispatch: # Interrupt:
mfc0 $k0, $13 # Get Cause register, again
beq $k0, 0, done # handled all outstanding interrupts
and $a0, $k0, BONK_INT_MASK # is there a bonk interrupt?
bne $a0, 0, bonk_interrupt
and $a0, $k0, TIMER_INT_MASK # is there a timer interrupt?
bne $a0, 0, timer_interrupt
and $a0, $k0, REQUEST_PUZZLE_INT_MASK
bne $a0, 0, request_puzzle_interrupt
# li $v0, PRINT_STRING # Unhandled interrupt types
# la $a0, unhandled_str
# syscall
j done
bonk_interrupt:
sw $0, BONK_ACK
#Fill in your code here
lw $t0, BOT_Y
bge $t0, 275, bonk_submit
lw $t0, BOT_X
blt $t0, 150, bonk_left
bonk_right:
lw $a0, BOT_X # X coordinate @a0
beq $a0, 160, right_counter
beq $t7, -1, right_start_work
bge $a0, 280, right_first_bonk
right_bins:
sw $0, PICKUP
sw $0, PICKUP
sw $0, PICKUP
sw $0, PICKUP
##move west to start
li $t0, 180
sw $t0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
li $t0, 10
sw $t0, VELOCITY
j interrupt_dispatch # see if other interrupts are waiting
right_first_bonk:
li $t0, 90
sw $t0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
sw $0, PICKUP
sw $0, PICKUP
sw $0, PICKUP
sw $0, PICKUP
li $t0, 180
sw $t0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
li $t0, 10
sw $t0, VELOCITY
li $t0, 500
right_first_bonk_loop:
add $t0, $t0, -1
bnez $t0, right_first_bonk_loop
li $t0, 175
sw $t0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
j interrupt_dispatch # see if other interrupts are waiting
right_counter:
sw $0, DROPOFF
li $t0, 1
sw $t0, DROPOFF
li $t0, 2
sw $t0, DROPOFF
li $t0, 3
sw $t0, DROPOFF
lw $t0, TIMER
blt $t0, MAX_TIME, right_continue_work
li $t0, 90
sw $t0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
li $t0, 10
sw $t0, VELOCITY
# sw $0, GET_BOOST
j interrupt_dispatch
right_continue_work:
bltz $t7, right_return_work
addi $t7, -1
beqz $t7, right_go_next_bin
##move east
sw $0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
li $t0, 10
sw $t0, VELOCITY
j interrupt_dispatch # see if other interrupts are waiting
right_go_next_bin:
lw $a1, BOT_Y # Y coordinate @a0
bge $a1, 170, right_return_appliance
li $t0, 33
sw $t0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
li $t0, 10
sw $t0, VELOCITY
jal adjust_fetch
move $t7, $v0
#sw $0, GET_BOOST
j interrupt_dispatch # see if other interrupts are waiting
right_return_work:
xor $s7, $s7, 1
move $a0, $s7
jal fetch_item
bnez $s7, right_return_work_long
li $t0, 0x00020009
sw $t0, SET_TILE
li $t0, 342
j right_return_work_endif
right_return_work_long:
li $t0, 0x0002000c
sw $t0, SET_TILE
li $t0, 354
sw $0, GET_BOOST
sw $0, GET_BOOST
right_return_work_endif:
sw $t0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
li $t0, 10
sw $t0, VELOCITY
li $t7, -1
# sw $0, GET_BOOST
j interrupt_dispatch # see if other interrupts are waiting
right_return_appliance:
#### get INGREDIENT first
li $a0, 0
jal fetch_item
li $t0, 280
sw $t0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
li $t0, 10
sw $t0, VELOCITY
li $t7, -1
li $t0, 0x00020009
sw $t0, SET_TILE
j interrupt_dispatch # see if other interrupts are waiting
right_start_work:
li $t0, 270
sw $t0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
add $t0, $t7, 4
sw $t0, DROPOFF
lw $s5, GET_TILE_INFO
sw $0, TIMER
j interrupt_dispatch # see if other interrupts are waiting
#### left
bonk_left:
lw $a0, BOT_X # X coordinate @a0
beq $a0, 139, left_counter
beq $t7, -1, left_start_work
blt $a0, 20, left_first_bonk
left_bins:
sw $0, PICKUP
sw $0, PICKUP
sw $0, PICKUP
sw $0, PICKUP
##move east to start
sw $0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
li $t0, 10
sw $t0, VELOCITY
j interrupt_dispatch # see if other interrupts are waiting
left_first_bonk:
li $t0, 90
sw $t0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
sw $0, PICKUP
sw $0, PICKUP
sw $0, PICKUP
sw $0, PICKUP
sw $0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
li $t0, 10
sw $t0, VELOCITY
li $t0, 500
left_first_bonk_loop:
add $t0, $t0, -1
bnez $t0, left_first_bonk_loop
li $t0, 5
sw $t0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
j interrupt_dispatch # see if other interrupts are waiting
left_counter:
sw $0, DROPOFF
li $t0, 1
sw $t0, DROPOFF
li $t0, 2
sw $t0, DROPOFF
li $t0, 3
sw $t0, DROPOFF
lw $t0, TIMER
blt $t0, MAX_TIME, left_continue_work
li $t0, 90
sw $t0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
li $t0, 10
sw $t0, VELOCITY
# sw $0, GET_BOOST
j interrupt_dispatch
left_continue_work:
bltz $t7, left_return_work
addi $t7, -1
beqz $t7, left_go_next_bin
##move west
li $t0, 180
sw $t0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
li $t0, 10
sw $t0, VELOCITY
j interrupt_dispatch # see if other interrupts are waiting
left_go_next_bin:
lw $a1, BOT_Y # Y coordinate @a0
bge $a1, 170, left_return_appliance
li $t0, 147
sw $t0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
li $t0, 10
sw $t0, VELOCITY
jal adjust_fetch
move $t7, $v0
#sw $0, GET_BOOST
j interrupt_dispatch # see if other interrupts are waiting
left_return_work:
xor $s7, $s7, 1
move $a0, $s7
jal fetch_item
bnez $s7, left_return_work_long
li $t0, 0x00020005
sw $t0, SET_TILE
li $t0, 198
j left_return_work_endif
left_return_work_long:
li $t0, 0x00020002
sw $t0, SET_TILE
li $t0, 186
sw $0, GET_BOOST
sw $0, GET_BOOST
left_return_work_endif:
sw $t0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
li $t0, 10
sw $t0, VELOCITY
li $t7, -1
# sw $0, GET_BOOST
j interrupt_dispatch # see if other interrupts are waiting
left_return_appliance:
#### get INGREDIENT first
li $a0, 0
jal fetch_item
li $t0, 260
sw $t0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
li $t0, 10
sw $t0, VELOCITY
li $t7, -1
li $t0, 0x00020005
sw $t0, SET_TILE
j interrupt_dispatch # see if other interrupts are waiting
left_start_work:
li $t0, 270
sw $t0, ANGLE
li $t0, 1
sw $t0, ANGLE_CONTROL
add $t0, $t7, 4
sw $t0, DROPOFF
# sw $t0, FINISH_APPLIANCE_INSTANT
lw $s5, GET_TILE_INFO
sw $0, TIMER
j interrupt_dispatch # see if other interrupts are waiting
bonk_submit:
li $s6, 1
jal submit
j interrupt_dispatch
request_puzzle_interrupt:
sw $0, REQUEST_PUZZLE_ACK
#Fill in your code here
# lw $t0, GET_MONEY
# bge $t0, 100, interrupt_dispatch
la $a0, puzzle
sw $a0, REQUEST_PUZZLE
#############################resolving process starts############################
li $a1, 'A' #marker
lw $t4, 0($a0) #row
lw $t5, 4($a0) #col
mul $t8, $t4, $t5 #size
add $t8, $t8, $a0 #base address - 8 for bitboard
li $a2, 0 #a2 = i
bne $t5, 32, i_outer_loop
i_outer_loop_32:
beq $a2, $t4, i_outer_end
mul $t0, $a2, $t5
add $t6, $t0, $a0 #puzzle address - 8 for each row
li $a3, 0 #a3 = j
li $s2, 8 #start of each block
######block 0 starts
puzzle_32_block0:
######prepare jumptable
lbu $t0, 8($t8)
# sw $t0 0xffff0080
sll $t0, $t0, 2
add $s3, $s4, $t0 #s4 : jumpboard base address
######
lb $t0, 8($t6)
bne $t0, $t9, puzzle_32_jump0_0
move $t2, $t6
jal floodfill_real
add $a1, $a1, 1
######jump 0 0 starts
puzzle_32_jump0_0:
lb $t1, 0($s3)
add $a3, $a3, $t1
add $t6, $t6, $t1
beq $a3, $s2, puzzle_32_block1
lb $t0, 8($t6)
bne $t0, $t9, puzzle_32_jump0_1
move $t2, $t6
jal floodfill_real
add $a1, $a1, 1
######
######jump 0 1 starts
puzzle_32_jump0_1:
lb $t1, 1($s3)
add $a3, $a3, $t1
add $t6, $t6, $t1
beq $a3, $s2, puzzle_32_block1
lb $t0, 8($t6)
bne $t0, $t9, puzzle_32_jump0_2
move $t2, $t6
jal floodfill_real
add $a1, $a1, 1
######
######jump 0 2 starts
puzzle_32_jump0_2:
lb $t1, 2($s3)
add $a3, $a3, $t1
add $t6, $t6, $t1
beq $a3, $s2, puzzle_32_block1
lb $t0, 8($t6)
bne $t0, $t9, puzzle_32_block1
move $t2, $t6
jal floodfill_real
add $a1, $a1, 1
######
######
######block 1 starts
puzzle_32_block1:
add $s2, $s2, 8
######prepare jumptable
lbu $t0, 9($t8)
# sw $t0 0xffff0080
sll $t0, $t0, 2
add $s3, $s4, $t0 #s4 : jumpboard base address
######
lb $t0, 8($t6)
bne $t0, $t9, puzzle_32_jump1_0
move $t2, $t6
jal floodfill_real
add $a1, $a1, 1
######jump 1 0 starts
puzzle_32_jump1_0:
lb $t1, 0($s3)
add $a3, $a3, $t1
add $t6, $t6, $t1
beq $a3, $s2, puzzle_32_block2
lb $t0, 8($t6)
bne $t0, $t9, puzzle_32_jump1_1
move $t2, $t6
jal floodfill_real
add $a1, $a1, 1
######
######jump 1 1 starts
puzzle_32_jump1_1:
lb $t1, 1($s3)
add $a3, $a3, $t1
add $t6, $t6, $t1
beq $a3, $s2, puzzle_32_block2
lb $t0, 8($t6)
bne $t0, $t9, puzzle_32_jump1_2
move $t2, $t6
jal floodfill_real
add $a1, $a1, 1
######
######jump 1 2 starts
puzzle_32_jump1_2:
lb $t1, 2($s3)
add $a3, $a3, $t1
add $t6, $t6, $t1
beq $a3, $s2, puzzle_32_block2
lb $t0, 8($t6)
bne $t0, $t9, puzzle_32_block2
move $t2, $t6
jal floodfill_real
add $a1, $a1, 1
######
######
######block 2 starts
puzzle_32_block2:
add $s2, $s2, 8
######prepare jumptable
lbu $t0, 10($t8)
# sw $t0 0xffff0080
sll $t0, $t0, 2
add $s3, $s4, $t0 #s4 : jumpboard base address
######
lb $t0, 8($t6)
bne $t0, $t9, puzzle_32_jump2_0
move $t2, $t6
jal floodfill_real
add $a1, $a1, 1
######jump 2 0 starts
puzzle_32_jump2_0:
lb $t1, 0($s3)
add $a3, $a3, $t1
add $t6, $t6, $t1
beq $a3, $s2, puzzle_32_block3
lb $t0, 8($t6)
bne $t0, $t9, puzzle_32_jump2_1
move $t2, $t6
jal floodfill_real
add $a1, $a1, 1
######
######jump 2 1 starts
puzzle_32_jump2_1:
lb $t1, 1($s3)
add $a3, $a3, $t1
add $t6, $t6, $t1
beq $a3, $s2, puzzle_32_block3
lb $t0, 8($t6)
bne $t0, $t9, puzzle_32_jump2_2
move $t2, $t6
jal floodfill_real
add $a1, $a1, 1
######
######jump 2 2 starts
puzzle_32_jump2_2:
lb $t1, 2($s3)
add $a3, $a3, $t1
add $t6, $t6, $t1
beq $a3, $s2, puzzle_32_block3
lb $t0, 8($t6)
bne $t0, $t9, puzzle_32_block3
move $t2, $t6
jal floodfill_real
add $a1, $a1, 1
######
######
######block 3 starts
puzzle_32_block3:
add $s2, $s2, 8
######prepare jumptable
lbu $t0, 11($t8)
# sw $t0 0xffff0080
sll $t0, $t0, 2
add $s3, $s4, $t0 #s4 : jumpboard base address
######
lb $t0, 8($t6)
bne $t0, $t9, puzzle_32_jump3_0
move $t2, $t6
jal floodfill_real
add $a1, $a1, 1
######jump 3 0 starts
puzzle_32_jump3_0:
lb $t1, 0($s3)
add $a3, $a3, $t1
add $t6, $t6, $t1
beq $a3, $s2, puzzle_32_line_end
lb $t0, 8($t6)
bne $t0, $t9, puzzle_32_jump3_1
move $t2, $t6
jal floodfill_real
add $a1, $a1, 1
######
######jump 3 1 starts
puzzle_32_jump3_1:
lb $t1, 1($s3)
add $a3, $a3, $t1
add $t6, $t6, $t1
beq $a3, $s2, puzzle_32_line_end
lb $t0, 8($t6)
bne $t0, $t9, puzzle_32_jump3_2
move $t2, $t6
jal floodfill_real
add $a1, $a1, 1
######
######jump 3 2 starts
puzzle_32_jump3_2:
lb $t1, 2($s3)
add $a3, $a3, $t1
add $t6, $t6, $t1
beq $a3, $s2, puzzle_32_line_end
lb $t0, 8($t6)
bne $t0, $t9, puzzle_32_line_end
move $t2, $t6
jal floodfill_real
add $a1, $a1, 1
######
######
puzzle_32_line_end:
add $t8, $t8, 5
add $a2, $a2, 1
j i_outer_loop_32
i_outer_loop:
beq $a2, $t4, i_outer_end
mul $t0, $a2, $t5
add $t6, $t0, $a0 #puzzle address - 8 for each row
li $a3, 0 #a3 = j
li $s2, 8 #start of each block
######block 0 starts
puzzle_block0:
######prepare jumptable
lbu $t0, 8($t8)
sll $t0, $t0, 2