-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspimbot.s
1755 lines (1491 loc) · 39.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
REQUEST_PUZZLE = 0xffff00d0 ## Puzzle
SUBMIT_SOLUTION = 0xffff00d4 ## Puzzle
BONK_INT_MASK = 0x1000
BONK_ACK = 0xffff0060
TIMER_INT_MASK = 0x8000
TIMER_ACK = 0xffff006c
REQUEST_PUZZLE_INT_MASK = 0x800 ## Puzzle
REQUEST_PUZZLE_ACK = 0xffff00d8 ## Puzzle
PICKUP = 0xffff00f4
SPAWN_MINIBOT = 0xffff00dc
BUILD_SILO = 0xffff2000
SELECT_IDLE = 0xffff00e4
SET_TARGET = 0xffff00e8
GET_KERNEL_LOCATIONS = 0xffff200c
SELECT_ID = 0xffff2004
GET_MINIBOT = 0xffff2014
GET_MAP = 0xffff00f0
PUZZLE_CNT = 0xffff2008
# Add any MMIO that you need here (see the Spimbot Documentation)
TSHLD = 5
CTR_LEFT = 14
CTR_TOP = 7
L_LEFT = 2
L_TOP = 20
R_LEFT = 29
R_TOP = 5
### Puzzle
GRIDSIZE = 16
signal: .word 0
has_puzzle: .word 0
puzzle_cnt: .word 1
finishing: .word 0
anchor: .word -1
oppo_puzzle: .word 0:3
puzzle: .half 0:2000
heap: .half 0:2000
location: .byte 0:1700
minibot: .word 0:30
atk_flag: .word 0
test_loc: .word 0
silo_built: .word 0
#### Puzzle
BNK_AGL: .word 45
three: .float 3.0
five: .float 5.0
PI: .float 3.141592
F180: .float 180.0
.text
main:
# Construct interrupt mask
li $t4, 0
or $t4, $t4, REQUEST_PUZZLE_INT_MASK # puzzle interrupt bit
or $t4, $t4, TIMER_INT_MASK # timer interrupt bit
or $t4, $t4, BONK_INT_MASK # timer interrupt bit
or $t4, $t4, 1 # global enable
mtc0 $t4, $12
#Fill in your code here
la $t0, puzzle
sw $t0, REQUEST_PUZZLE
j center_main
main_dispatch:
lw $t0, TIMER
bgt $t0, 9000000, finish
lw $t0, signal
beq $t0, 1 mission_solve6
beq $t0, 0 mission_move_main
finish:
li $t0, 1
sw $t0, finishing
lw $t0, BOT_X
lw $t1, BOT_Y
lw $t0, signal
blt $t0, 2, ftl_skip
bne $t0, 2, ftl_skip2
jal transfer_l2m
j ftl_skip
ftl_skip2:
jal transfer_r2m
ftl_skip:
li $a0 14
li $a1 13
jal move_main
top_left:
li $s4 10
sw $s4 VELOCITY
li $s3 1
li $t4 225
sw $t4 ANGLE
sw $s3 ANGLE_CONTROL
li $a0 130
jal stop_timer
li $t4 135
sw $t4 ANGLE
sw $s3 ANGLE_CONTROL
sw $s4 VELOCITY
li $a0 16
jal stop_timer
li $t4 40
sw $t4 ANGLE
sw $s3 ANGLE_CONTROL
sw $s4 VELOCITY
li $a0 55
jal stop_timer
li $t4 95
sw $t4 ANGLE
sw $s3 ANGLE_CONTROL
sw $s4 VELOCITY
li $a0 110
jal stop_timer
li $t4 325
sw $t4 ANGLE
sw $s3 ANGLE_CONTROL
sw $s4 VELOCITY
li $a0 90
jal stop_timer
li $t4 43
sw $t4 ANGLE
sw $s3 ANGLE_CONTROL
sw $s4 VELOCITY
li $a0 275
jal stop_timer
li $t4 0
sw $t4 ANGLE
sw $s3 ANGLE_CONTROL
sw $s4 VELOCITY
li $a0 20
jal stop_timer
li $t4 230
sw $t4 ANGLE
sw $s3 ANGLE_CONTROL
sw $s4 VELOCITY
li $a0 70
jal stop_timer
li $t4 260
sw $t4 ANGLE
sw $s3 ANGLE_CONTROL
sw $s4 VELOCITY
li $a0 100
jal stop_timer
li $t4 30
sw $t4 ANGLE
sw $s3 ANGLE_CONTROL
sw $s4 VELOCITY
j top_left
bottom_right:
li $s6 0
li $s8 0
li $s7 0
fbr_get_loop:
beq $s6, 10, fbr_out
jal fin_left_target
move $a0 $s8
move $a1 $s7
jal move_main
addi $s6 $s6 1
j fbr_get_loop
fbr_out:
j bottom_right
j finish
fin_left_target:
la $t9 location
sw $t9 GET_KERNEL_LOCATIONS($0)
#ensure safety
li $t5 13 #right bound
li $t6 20 #bottom bound
bge $s7 $t6 skipv0resetfl
li $s7 0
skipv0resetfl:
bge $s8 $t5 skipv1resetfl
li $s8 0
skipv1resetfl:
li $t6 40
addi $t9 $t9 4
mt_outerfl:
bge $s7 20 mt_outer_exitfl
mt_innerfl:
bge $s8 13 mt_inner_exitfl
mul $t8 $t6 $s7
add $t8 $t8 $s8
add $t8 $t8 $t9
lb $t8 0($t8)
blt $t8, TSHLD mt_next_locfl
jr $ra
mt_next_locfl:
addi $s8 $s8 1
j mt_innerfl
mt_inner_exitfl:
li $s8 0
addi $s7 $s7 1
j mt_outerfl
mt_outer_exitfl:
li $s7 0
jr $ra
# right_target:
# la $t9 location
# sw $t9 GET_KERNEL_LOCATIONS($0)
# #ensure safety
# li $t5 37 #right bound
# li $t6 17
# bge $s7 $t6 skipv0reset
# li $s7 R_TOP
# skipv0reset2:
# bge $s8 $t5 skipv1reset
# li $s8 R_LEFT
# skipv1reset2:
# li $t6 40
# addi $t9 $t9 4
# mt_outer2:
# bge $s7 17 mt_outer_exit2
# mt_inner2:
# bge $s8 37 mt_inner_exit2
# mul $t8 $t6 $s7
# add $t8 $t8 $s8
# add $t8 $t8 $t9
# lb $t8 0($t8)
# blt $t8, TSHLD mt_next_loc2
# jr $ra
# mt_next_loc2:
# addi $s8 $s8 1
# j mt_inner2
# mt_inner_exit2:
# li $s8 R_LEFT
# addi $s7 $s7 1
# j mt_outer2
# mt_outer_exit2:
# li $s7 R_TOP
# jr $ra
mission_solve6:
lw $t0, TIMER
addi $t0 $t0 10
sw $t0, TIMER
la $t0, minibot
sw $t0, GET_MINIBOT
lw $t0, minibot
bne $t0, $0, main_dispatch
la $t0, oppo_puzzle
sw $t0, PUZZLE_CNT
lw $t0 4($t0) ##oppo_puzzle
bgt $t0, 3, need_solve
jal get_oppo_silo
lw $t0, atk_flag
beq $t0, 1, need_solve
j main_dispatch
need_solve:
lw $s0, puzzle_cnt
puzzle_loop:
beq $s0 $0 out_puzzle_loop ## when solved 4 puzzles go collect
la $t1 has_puzzle
la $a0 puzzle
la $a1 heap
li $a2 0
li $a3 0
while:
lw $t2 0($t1)
bne $0 $t2 start_solving
j while
start_solving:
jal slow_solve_dominosa
la $a0 puzzle
sw $a0 REQUEST_PUZZLE
la $a1 heap
sw $a1 SUBMIT_SOLUTION
sw $0 has_puzzle
addi $s0 $s0 -1
j puzzle_loop
out_puzzle_loop:
li $t0 1
sw $t0, SPAWN_MINIBOT
jal get_oppo_silo
lw $t0, atk_flag
beq $t0, 0, non_atk
la $t0, minibot
sw $t0, GET_MINIBOT
lw $t1, minibot
beq $t1, 0, non_atk
lw $t0, 4($t0)
sw $t0, SELECT_ID
lw $t0, test_loc
sw $t0, SET_TARGET
non_atk:
j main_dispatch
center_main:
## moves the bot to the center of the map
lw $t0 BOT_X($0)
blt $t0 160 upper_start
li $t1 225
j start_end
upper_start:
li $t1 45
start_end:
sw $t1 ANGLE($0)
li $t1 1
sw $t1 ANGLE_CONTROL($0)
li $a0 20
li $a1 20
jal dist
li $t0 10
sw $t0 VELOCITY($0)
move $a0 $v0
li $t8 8
mul $a0 $a0 $t8
jal stop_timer ## move to 20 18?
j main_dispatch
mission_move_main:
lw $t8, TIMER
li $t9 100
add $t8 $t8 $t9
sw $t8, TIMER
get_more:
lw $t0, anchor
beq $t0, 0, middle_get
beq $t0, 1, middle_get1
beq $t0, 2, left_get
beq $t0, 3, right_get
middle_get:
li $s6 0
li $s8 CTR_LEFT
li $s7 CTR_TOP
middle_get_loop:
beq $s6, 10, middle_out
jal main_target
bne $s8, CTR_LEFT, valid_t
bne $s7, CTR_TOP, valid_t
j middle_out
valid_t:
move $a0 $s8
move $a1 $s7
jal move_main
addi $s6 $s6 1
j middle_get_loop
middle_out:
jal transfer_m2l
li $t0, 2
sw $t0, anchor
j get_out
middle_get1:
li $s6 0
li $s8 CTR_LEFT
li $s7 CTR_TOP
middle_get_loop1:
beq $s6, 10, middle_out1
jal main_target
bne $s8, CTR_LEFT, valid_t1
bne $s7, CTR_TOP, valid_t1
j middle_out1
valid_t1:
move $a0 $s8
move $a1 $s7
jal move_main
addi $s6 $s6 1
j middle_get_loop1
middle_out1:
jal transfer_m2r
li $t0, 3
sw $t0, anchor
j get_out
left_get:
li $s8 L_LEFT
li $s7 L_TOP
li $s6 0
left_get_loop:
beq $s6, 10, left_out
jal left_target
bne $s8, L_LEFT, valid_t2
bne $s7, L_TOP, valid_t2
j left_out
valid_t2:
move $a0 $s8
move $a1 $s7
jal move_main
addi $s6 $s6 1
j left_get_loop
left_out:
jal transfer_l2m
li $t0, 1
sw $t0, anchor
j get_out
right_get:
li $s8 R_LEFT
li $s7 R_TOP
li $s6 0
right_get_loop:
beq $s6, 10, right_out
jal right_target
bne $s8, R_LEFT, valid_t3
bne $s7, R_TOP, valid_t3
j right_out
valid_t3:
move $a0 $s8
move $a1 $s7
jal move_main
addi $s6 $s6 1
j right_get_loop
right_out:
jal transfer_r2m
li $t0, 0
sw $t0, anchor
j get_out
get_out:
jal get_oppo_silo
lw $t0, atk_flag
beq $t0, 0, non_atk
la $t0, minibot
sw $t0, GET_MINIBOT
lw $t1, minibot
beq $t1, 0, non_atk1
lw $t0, 4($t0)
sw $t0, SELECT_ID
lw $t0, test_loc
sw $t0, SET_TARGET
non_atk1:
lw $t8 signal
bne $t8, 0, main_dispatch
j get_more
#test_field:
# lw $t8, TIMER
# li $t9 10000
# add $t8 $t8 $t9
# sw $t8, TIMER
#your code
# lw $t0, puzzle_cnt
# beq $t0, 4, enter_move_again
# sub $sp, $sp, 4
# sw $ra, 0($sp)
# li $t0, 1
# sw $t0, SPAWN_MINIBOT
# sw $t0, SPAWN_MINIBOT
# sw $t0, SPAWN_MINIBOT
#
# li $t0, 0x1a06
# sw $t0, SELECT_IDLE
# sw $t0, SET_TARGET
# li $a0, 56
# jal stop_timer
# li $t0, 0x1a06 ## build silo at (6,26)
# sw $t0, BUILD_SILO
# li $t8, 1
# sw $t8, silo_built
# lw $ra, 0($sp)
# addi $sp, $sp, 4
# jr $ra
#
# main_mbot: ## spawn 2 bots and move to silo
# li $t0 1
# sw $t0, SPAWN_MINIBOT
# sw $t0, SPAWN_MINIBOT
# sw $t0, SPAWN_MINIBOT
# sw $t0, SPAWN_MINIBOT
# li $t0, 0x00001a06
# sw $t0, SELECT_IDLE
# sw $t0, SET_TARGET
# jr $ra
# enter_move_again:
# jal get_next_location
# move_again:
# la $a1 test_loc
# jal move_minibot
# la $a0 400
# jal stop_timer
# sw $t0, SELECT_IDLE
# li $t0, 0x1a06
# sw $t0, SET_TARGET
# la $a0 500
# jal stop_timer
# lw $t5, signal
# bne $t5, 2, main_dispatch
# j move_again
# j test_field
get_oppo_silo:
la $t0 location
sw $t0, GET_MAP
li $t1 0
li $t4 3
li $t5 2
oppo_oloop:
beq $t1, 1600, oppo_oout
add $t3 $t0 $t1
lbu $t3 0($t3)
bne $t1, 1180, test_bk
li $v0 1
move $a0 $t3
syscall
test_bk:
beq $t3 $t4 storeturn
beq $t3 $t5 storeturn
addi $t1 $t1 1
j oppo_oloop
oppo_oout:
li $t4 0
sw $t4, atk_flag
jr $ra
storeturn:
li $t4 1
sw $t4, atk_flag
li $t4 40
div $t5 $t1 $t4 #y
mul $t4 $t4 $t5
sub $t4 $t1 $t4 #x
li $t6 8
sll $t5 $t5 $t6
or $t4 $t4 $t5
sw $t4, test_loc
jr $ra
#get_next_location:
la $t9 location
sw $t9 GET_KERNEL_LOCATIONS($0)
la $t4 test_loc
add $t9 4
li $t5 0 # find 10
loopp:
bge $t5 10 loop_over
lw $t6, TIMER
div $t8, $t6, 15
div $t9, $t6, 13
mul $t9, $t9, 13
sub $t7, $t6, $t9
mul $t8, $t8, 15
sub $t6 $t6 $t8
li $a1 40
addi $t7 $t7 20
addi $t6 $t6 2
la $t9 location
addi $t9 $t9 4
loc_outer:
bge $t6 34 loc_outer_exit
loc_inner:
bge $t7 17 loc_inner_exit
mul $t8 $a1 $t6
add $t8 $t8 $t7
add $t8 $t8 $t9
lb $t8 0($t8)
bgt $t8 3 loc_outer_exit
addi $t7 1
j loc_inner
loc_inner_exit:
li $t7 20
addi $t6 1
j loc_outer
loc_outer_exit:
ble $t8 3 gnls
sll $t8 $t6 8
or $t8 $t7 $t8 ###reversed
sw $t8 0($t4)
add $t4 4
add $t5 1
gnls:
j loopp
loop_over:
jr $ra
move_main:
addi $sp $sp -20
sw $ra 0($sp)
sw $s0 4($sp)
sw $s1 8($sp)
sw $a0 12($sp)
sw $a1 16($sp)
# la $t0, minibot
# sw $t0, GET_MINIBOT
# lw $t1, minibot
# bne $t1, $zero, label
#
# label:
# jal move_minibot
#
# lw $a0 12($sp)
# lw $a1 16($sp)
lw $t0 BOT_X #x
lw $t1 BOT_Y #y
li $t8 8
# div $t0 $t0 $t8
# div $t1 $t1 $t8
mul $a0 $a0 $t8
mul $a1 $a1 $t8
slti $t2 $t0 160 #x < 160
slti $t3 $t1 160 #y < 160
not $t4 $t2
not $t5 $t3
sub $s0 $a0 $t0
sub $s1 $a1 $t1
ble $s0 $0 x_offset_neg
x_offset_pos:
ble $s1 $0 xpyn
xpyp:
ble $t3 $t2 xy_move
j yx_move
xpyn:
ble $t5 $t2 xy_move
j yx_move
x_offset_neg:
ble $s1 $0 xnyn
xnyp:
ble $t5 $t2 yx_move
j xy_move
xnyn:
ble $t3 $t2 yx_move
j xy_move
xy_move:
move $a0 $s0
abs $a0 $a0
ble $s0 $0 xleft
xright:
li $t8 0
sw $t8 ANGLE
li $t8 1
sw $t8 ANGLE_CONTROL
li $t8 10
sw $t8 VELOCITY
jal stop_timer
ble $s1 $0 xyup
j xydown
xleft:
li $t8 180
sw $t8 ANGLE
li $t8 1
sw $t8 ANGLE_CONTROL
li $t8 10
sw $t8 VELOCITY
jal stop_timer
ble $s1 $0 xyup
j xydown
xyup:
li $t8 270
sw $t8 ANGLE
li $t8 1
sw $t8 ANGLE_CONTROL
li $t8 10
sw $t8 VELOCITY
move $a0 $s1
neg $a0 $a0
jal stop_timer
j move_end
xydown:
li $t8 90
sw $t8 ANGLE
li $t8 1
sw $t8 ANGLE_CONTROL
li $t8 10
sw $t8 VELOCITY
move $a0 $s1
jal stop_timer
j move_end
yx_move:
ble $s1 $0 yup
ydown:
li $t8 90
sw $t8 ANGLE
li $t8 1
sw $t8 ANGLE_CONTROL
li $t8 10
sw $t8 VELOCITY
move $a0 $s1
jal stop_timer
ble $s0 $0 yxleft
j yxright
yup:
li $t8 270
sw $t8 ANGLE
li $t8 1
sw $t8 ANGLE_CONTROL
li $t8 10
sw $t8 VELOCITY
move $a0 $s1
neg $a0 $a0
jal stop_timer
ble $s0 $0 yxleft
j yxright
yxleft:
li $t8 180
sw $t8 ANGLE
li $t8 1
sw $t8 ANGLE_CONTROL
li $t8 10
sw $t8 VELOCITY
move $a0 $s0
neg $a0 $a0
jal stop_timer
j move_end
yxright:
li $t8 0
sw $t8 ANGLE
li $t8 1
sw $t8 ANGLE_CONTROL
li $t8 10
sw $t8 VELOCITY
move $a0 $s0
jal stop_timer
j move_end
move_end:
lw $ra 0($sp)
lw $s0 4($sp)
lw $s1 8($sp)
addi $sp $sp 20
jr $ra
main_target:
la $t9 location
sw $t9 GET_KERNEL_LOCATIONS($0)
#ensure safety
li $t5 26
li $t6 33
bgt $s7 $t6 skipv0reset
li $s7 CTR_TOP
skipv0reset:
bgt $s8 $t5 skipv1reset
li $s8 CTR_LEFT
skipv1reset:
li $t6 40
addi $t9 $t9 4
mt_outer:
bge $s7 33 mt_outer_exit
mt_inner:
bge $s8 26 mt_inner_exit
mul $t8 $t6 $s7
add $t8 $t8 $s8
add $t8 $t8 $t9
lb $t8 0($t8)
blt $t8, TSHLD, mt_next_loc
jr $ra
mt_next_loc:
addi $s8 $s8 1
j mt_inner
mt_inner_exit:
li $s8 CTR_LEFT
addi $s7 $s7 1
j mt_outer
mt_outer_exit:
li $s7 CTR_TOP
jr $ra
left_target:
la $t9 location
sw $t9 GET_KERNEL_LOCATIONS($0)
#ensure safety
li $t5 11 #right bound
li $t6 34
bge $s7 $t6 skipv0reset1
li $s7 L_TOP
skipv0reset1:
bge $s8 $t5 skipv1reset1
li $s8 L_LEFT
skipv1reset1:
li $t6 40
addi $t9 $t9 4
mt_outer1:
bge $s7 34 mt_outer_exit1
mt_inner1:
bge $s8 11 mt_inner_exit1
mul $t8 $t6 $s7
add $t8 $t8 $s8
add $t8 $t8 $t9
lb $t8 0($t8)
blt $t8, TSHLD mt_next_loc1
jr $ra
mt_next_loc1:
addi $s8 $s8 1
j mt_inner1
mt_inner_exit1:
li $s8 L_LEFT
addi $s7 $s7 1
j mt_outer1
mt_outer_exit1:
li $s7 L_TOP
jr $ra
right_target:
la $t9 location
sw $t9 GET_KERNEL_LOCATIONS($0)
#ensure safety
li $t5 37 #right bound
li $t6 17
bge $s7 $t6 skipv0reset2
li $s7 R_TOP
skipv0reset2:
bge $s8 $t5 skipv1reset2
li $s8 R_LEFT
skipv1reset2:
li $t6 40
addi $t9 $t9 4
mt_outer2:
bge $s7 17 mt_outer_exit2
mt_inner2:
bge $s8 37 mt_inner_exit2
mul $t8 $t6 $s7
add $t8 $t8 $s8
add $t8 $t8 $t9
lb $t8 0($t8)
blt $t8, TSHLD mt_next_loc2
jr $ra
mt_next_loc2:
addi $s8 $s8 1
j mt_inner2
mt_inner_exit2:
li $s8 R_LEFT
addi $s7 $s7 1
j mt_outer2
mt_outer_exit2:
li $s7 R_TOP
jr $ra
transfer_m2l:
addi $sp $sp -4
sw $ra 0($sp)
li $a0 15
li $a1 28
jal move_main
li $t0 180
sw $t0, ANGLE
li $t0 1
sw $t0, ANGLE_CONTROL
li $t0 10
sw $t0, VELOCITY
li $a0 56
jal stop_timer
lw $ra 0($sp)
addi $sp $sp 4
jr $ra
transfer_l2m:
addi $sp $sp -4
sw $ra 0($sp)
li $a0 7
li $a1 28
jal move_main
li $t0 0
sw $t0, ANGLE
li $t0 1
sw $t0, ANGLE_CONTROL
li $t0 10
sw $t0, VELOCITY
li $a0 56
jal stop_timer
lw $ra 0($sp)
addi $sp $sp 4
jr $ra
transfer_m2r:
addi $sp $sp -4
sw $ra 0($sp)
li $a0 25
li $a1 12
jal move_main
li $t0 0
sw $t0, ANGLE
li $t0 1
sw $t0, ANGLE_CONTROL
li $t0 10
sw $t0, VELOCITY
li $a0 56
jal stop_timer
lw $ra 0($sp)
addi $sp $sp 4
jr $ra
transfer_r2m:
addi $sp $sp -4
sw $ra 0($sp)
li $a0 33
li $a1 12
jal move_main
li $t0 180