-
Notifications
You must be signed in to change notification settings - Fork 1
/
lab3.s
1061 lines (1000 loc) · 20.3 KB
/
lab3.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
.equ SEG_A,0x80
.equ SEG_B,0x40
.equ SEG_C,0x20
.equ SEG_D,0x08
.equ SEG_E,0x04
.equ SEG_F,0x02
.equ SEG_G,0x01
.equ SEG_P,0x10
Digits:
.word SEG_A|SEG_B|SEG_C|SEG_D|SEG_E|SEG_G @0
.word SEG_B|SEG_C @1
.word SEG_A|SEG_B|SEG_F|SEG_E|SEG_D @2
.word SEG_A|SEG_B|SEG_F|SEG_C|SEG_D @3
.word SEG_G|SEG_F|SEG_B|SEG_C @4
.word SEG_A|SEG_G|SEG_F|SEG_C|SEG_D @5
.word SEG_A|SEG_G|SEG_F|SEG_E|SEG_D|SEG_C @6
.word SEG_A|SEG_B|SEG_C @7
.word SEG_A|SEG_B|SEG_C|SEG_D|SEG_E|SEG_F|SEG_G @8
.word SEG_A|SEG_B|SEG_F|SEG_G|SEG_C @9
.word 0 @Blank display
.text
bl initialize @gives array in r9 and score in r7
bl arrayprinter
STMFD sp!, {r0-r2}
mov r0, #20
mov r1, #0
ldr r2,=gameintroduction
swi 0x204
mov r1, #2
ldr r2,=oneiswhite
swi 0x204
mov r1, #3
ldr r2,=twoisblack
swi 0x204
mov r1, #5
ldr r2, =madeby
swi 0x204
mov r1, #6
ldr r2, =akshatkhare
swi 0x204
mov r1, #7
ldr r2, =divyanshusaxena
swi 0x204
LDMFD sp!, {r0-r2}
mov r8,#1 @chance of player
b gameundergoing
endgame:
STMFD sp!,{r0-r2}
mov r0,#0
mov r1,#11
ldr r2,=EndMessage
swi 0x204
LDMFD sp!,{r0-r2}
b totalexit
gameundergoing:
STMFD sp!,{r0,r2}
mov r0,r8
ldr r2,=Digits
ldr r0,[r2,r0,lsl#2]
swi 0x200
LDMFD sp!,{r0,r2}
takeinput:
mov r0, #12
swi 0x208
mov r0, #13
swi 0x208
mov r0,#0
mov r1,#12
ldr r2,=Promptforpressx
swi 0x204
mov r3, #0
mov r0, #0
xinterrupt:
swi 0x203
cmp r0, r3
beq xinterrupt
bl computelogtwo
ldr r6,=IndexArray
str r1,[r6]
mov r5,r1 @x-coordinate as in mathematical 2d array
mov r0,#8
mov r1,#12
mov r2, r5
swi 0x205
mov r0,#0
mov r1,#13
ldr r2,=Promptforpressy
swi 0x204
mov r3, #0
mov r0,#0
yinterrupt:
swi 0x203
cmp r0, r3
beq yinterrupt
bl computelogtwo
sub r1,r1,#8 @ Required
str r1,[r6,#4]
mov r5,r1 @y-coordinate as in mathematical 2d array
mov r0,#8
mov r1,#13
mov r2, r5
swi 0x205
mov r0,#0
mov r3,#0
confirmationbutton:
swi 0x202
cmp r0, r3
beq confirmationbutton
cmp r0, #0x02
beq confirmed
cmp r0, #0x01
beq takeinput
@Now we must call the function checkvalidity
confirmed:
mov r0, #0x03
swi 0x201
mov r0, #0
str r0, [r6,#64] @for type of checkvalidity when the loop isn't changed
bl checkvalidity
bl scoreupdate
bl arrayprinter
mov r0,#1
cmp r0, r4
beq twasvalidmove
b twasinvalidmove
twasvalidmove:
mov r8, r5
mov r0, #0x02
swi 0x201
checkifmoveavailible:
mov r0,#0
str r0,[r6]
str r0,[r6,#4]
str r0,[r6,#8]
mov r0, #1
str r0, [r6,#64]
loopcheckifmoveavailible:
bl checkvalidity
@r4 has the boolean
mov r0,#1
cmp r0,r4
beq yesthereisavalidmoveavailible
ldr r0, [r6,#8]
add r0, r0,#1
str r0, [r6,#8]
cmp r0,#65
beq novalidmoveavailible
b getxandyfromnumber
gotxandyfromnumber:
b loopcheckifmoveavailible
@b novalidmoveavailible
novalidmoveavailible:
ldr r0, [r6,#68]
cmp r0, #1
beq endgame
ldr r2,=ChancePassed
mov r0, #0
mov r1, #14
swi 0x204
mov r0, #1
str r0, [r6,#68]
mov r1, #3
rsb r8, r8, r1
b checkifmoveavailible
b endgame
yesthereisavalidmoveavailible:
mov r0, #14
swi 0x208
mov r0, #0
str r0, [r6,#68]
b gameundergoing
getxandyfromnumber:
STMFD sp!, {r0-r2}
ldr r0, [r6,#8]
mov r1, r0, LSR #3
mov r2, r1, LSL #3
sub r2, r0, r2
str r1, [r6,#4]
str r2, [r6,#0]
LDMFD sp!, {r0-r2}
b gotxandyfromnumber
twasinvalidmove:
mov r0, #0x01
swi 0x201
b gameundergoing
@b endgame
checkvalidity:
STMFD sp!, {lr}
@STMFD sp!,{r0-r6} @ r8 -> dynamic current turn, r5 -> x-coordinate, r6 -> y-coordinate, r4 -> dynamic other player's turn
@ mov r2, r5
@ mov r3, r6
rsb r5,r8,#3 @other player
@r3 -> maintains a counter on how many times the value flipped
ldr r3, [r6]
str r3,[r6,#16]
ldr r4, [r6,#4]
str r4,[r6,#20]
mov r1,#8
mla r0,r1,r4,r3
str r0,[r6,#8]
ldrb r4,[r9,r0] @r4 is 8*r6 +r5
str r4, [r6,#12] @r6 has structure [x,y,8*y+x,r9[8*y+x],x',y',8*y'+x,r9[8*y'+x']]
mov r0, #0 @[0,4,8, 12, 16,20,24, 28]
cmp r4,r0
bne invalidmove
b horizontalright
endhorizontalright:
@[r6,#32] has the boolean
ldr r0, [r6,#64]
cmp r0, #1
bne continueendhorizontalright
ldr r0, [r6,#32]
cmp r0,#1
beq hasvalidmove
continueendhorizontalright:
b horizontalleft
endhorizontalleft:
@[r6,#36] has the boolean
ldr r0, [r6,#64]
cmp r0, #1
bne continueendhorizontalleft
ldr r0, [r6,#36]
cmp r0,#1
beq hasvalidmove
continueendhorizontalleft:
b verticalup
endverticalup:
@[r6,#40] has the boolean
ldr r0, [r6,#64]
cmp r0, #1
bne continueendverticalup
ldr r0, [r6,#40]
cmp r0,#1
beq hasvalidmove
continueendverticalup:
b verticaldown
endverticaldown:
@[r6,#44] has the boolean
ldr r0, [r6,#64]
cmp r0, #1
bne continueendverticaldown
ldr r0, [r6,#44]
cmp r0,#1
beq hasvalidmove
continueendverticaldown:
b forwardup
endforwardup:
@[r6,#48] has the boolean
ldr r0, [r6,#64]
cmp r0, #1
bne continueendforwardup
ldr r0, [r6,#48]
cmp r0,#1
beq hasvalidmove
continueendforwardup:
b forwarddown
endforwarddown:
@[r6,#52] has the boolean
ldr r0, [r6,#64]
cmp r0, #1
bne continueendforwarddown
ldr r0, [r6,#52]
cmp r0,#1
beq hasvalidmove
continueendforwarddown:
b backup
endbackup:
@[r6,#56] has the boolean
ldr r0, [r6,#64]
cmp r0, #1
bne continueendendbackup
ldr r0, [r6,#56]
cmp r0,#1
beq hasvalidmove
continueendendbackup:
b backdown
endbackdown:
@[r6,#60] has the boolean
ldr r0, [r6,#64]
cmp r0, #1
bne continueendendbackdown
ldr r0, [r6,#60]
cmp r0,#1
beq hasvalidmove
continueendendbackdown:
ldr r4, [r6,#32]
mov r3, #1
cmp r3,r4
beq hasvalidmove
ldr r4, [r6,#36]
cmp r3,r4
beq hasvalidmove
ldr r4, [r6,#40]
cmp r3,r4
beq hasvalidmove
ldr r4, [r6,#44]
cmp r3,r4
beq hasvalidmove
ldr r4, [r6,#48]
cmp r3,r4
beq hasvalidmove
ldr r4, [r6,#52]
cmp r3,r4
beq hasvalidmove
ldr r4, [r6,#56]
cmp r3,r4
beq hasvalidmove
ldr r4, [r6,#60]
cmp r3,r4
beq hasvalidmove
b invalidmove
horizontalright:
@STMFD sp! , {r5-r6}
mov r0, #6 @check if y==5 or y==7
ldr r4,[r6,#0]
cmp r0,r4
ble notvalidhorizontalright
@STMFD sp!, r4
ldr r4,[r6,#8]
add r4, r4,#1
str r4,[r6,#24]
ldr r0,[r6,#0]
add r0, r0,#1
str r0,[r6,#16]
ldrb r0,[r9,r4] @check if r5+1 is otherone or not
str r0,[r6,#28]
cmp r0, r5
beq loophorizontalright
b notvalidhorizontalright
loophorizontalright:
ldr r4,[r6,#24]
add r4, r4,#1
str r4,[r6,#24]
ldr r4,[r6,#16]
add r4,r4,#1
str r4,[r6,#16]
mov r0,#8
cmp r0, r4
beq notvalidhorizontalright
ldr r4,[r6,#24]
ldrb r0, [r9,r4]
mov r1, #0
cmp r1, r0
beq notvalidhorizontalright
cmp r0, r5
beq loophorizontalright
cmp r0,r8
beq foundhorizontalright
foundhorizontalright:
ldr r0, [r6,#64]
cmp r0, #1
beq skipendvalidhorizontalright
ldr r4, [r6,#24]
ldr r3, [r6,#8]
b loopoffoundhorizontalright
loopoffoundhorizontalright:
sub r4,r4,#1
cmp r3,r4
beq endvalidhorizontalright
strb r8, [r9,r4]
b loopoffoundhorizontalright
@LDMFD sp! , r4
notvalidhorizontalright:
mov r4,#0
str r4,[r6,#32]
b endhorizontalright
endvalidhorizontalright:
str r4, [r6,#24]
ldr r4, [r6,#8]
strb r8, [r9,r4]
skipendvalidhorizontalright:
mov r4,#1
str r4, [r6,#32]
b endhorizontalright
horizontalleft:
mov r0, #1
ldr r4, [r6,#0]
cmp r0, r4
bge notvalidhorizontalleft
ldr r4, [r6,#8]
sub r4, r4, #1
str r4, [r6,#24]
ldr r0, [r6,#0]
sub r0,r0,#1
str r0, [r6,#16]
ldrb r0, [r9,r4]
str r0, [r6,#28]
cmp r0, r5
beq loophorizontalleft
b notvalidhorizontalleft
loophorizontalleft:
ldr r4, [r6,#24]
sub r4, r4,#1
str r4, [r6,#24]
ldr r4, [r6,#16]
sub r4,r4,#1
str r4, [r6,#16]
mov r0, #-1
cmp r0, r4
beq notvalidhorizontalleft
ldr r4,[r6,#24]
ldrb r0,[r9,r4]
mov r1,#0
cmp r1, r0
beq notvalidhorizontalleft
cmp r0, r5
beq loophorizontalleft
cmp r0, r8
beq foundhorizontalleft
foundhorizontalleft:
ldr r0, [r6,#64]
cmp r0, #1
beq skipendvalidhorizontalleft
ldr r4, [r6,#24]
ldr r3, [r6,#8]
b loopoffoundhorizontalleft
loopoffoundhorizontalleft:
add r4, r4, #1
cmp r3, r4
beq endvalidhorizontalleft
strb r8, [r9,r4]
b loopoffoundhorizontalleft
notvalidhorizontalleft:
mov r4, #0
str r4, [r6,#36]
b endhorizontalleft
endvalidhorizontalleft:
str r4, [r6,#24]
ldr r4, [r6,#8]
strb r8, [r9,r4]
skipendvalidhorizontalleft:
mov r4, #1
str r4, [r6, #36]
b endhorizontalleft
verticalup:
mov r0, #1
ldr r4, [r6,#4]
cmp r0, r4
bge notvalidverticalup
ldr r4, [r6,#8]
sub r4,r4,#8
str r4, [r6,#24]
ldr r0, [r6,#4]
sub r0,r0,#1
str r0, [r6,#20]
ldrb r0, [r9,r4]
str r0, [r6,#28]
cmp r0, r5
beq loopverticalup
b notvalidverticalup
loopverticalup:
ldr r4, [r6,#24]
sub r4, r4, #8
str r4, [r6,#24]
ldr r4, [r6,#20]
sub r4,r4,#1
str r4, [r6,#20]
mov r0,#-1
cmp r0,r4
beq notvalidverticalup
ldr r4, [r6,#24]
ldrb r0, [r9, r4]
mov r1, #0
cmp r1, r0
beq notvalidverticalup
cmp r0, r5
beq loopverticalup
cmp r0, r8
beq foundverticalup
foundverticalup:
ldr r0, [r6,#64]
cmp r0, #1
beq skipendvalidverticalup
ldr r4, [r6,#24]
ldr r3, [r6,#8]
b loopoffoundverticalup
loopoffoundverticalup:
add r4, r4, #8
cmp r3, r4
beq endvalidverticalup
strb r8, [r9,r4]
b loopoffoundverticalup
notvalidverticalup:
mov r4,#0
str r4, [r6, #40]
b endverticalup
endvalidverticalup:
str r4, [r6, #24]
ldr r4, [r6,#8]
strb r8, [r9,r4]
skipendvalidverticalup:
mov r4,#1
str r4, [r6,#40]
b endverticalup
verticaldown:
mov r0, #6
ldr r4, [r6,#4]
cmp r0, r4
ble notvalidverticaldown
ldr r4, [r6,#8]
add r4, r4, #8
str r4, [r6,#24]
ldr r0, [r6,#4]
add r0,r0,#1
str r0, [r6,#20]
ldrb r0, [r9,r4]
str r0, [r6,#28]
cmp r0, r5
beq loopverticaldown
b notvalidverticaldown
loopverticaldown:
ldr r4, [r6,#24]
add r4, r4, #8
str r4, [r6,#24]
ldr r4, [r6,#20]
add r4,r4,#1
str r4, [r6,#20]
mov r0,#8
cmp r0,r4
beq notvalidverticaldown
ldr r4, [r6,#24]
ldrb r0, [r9, r4]
mov r1, #0
cmp r1, r0
beq notvalidverticaldown
cmp r0, r5
beq loopverticaldown
cmp r0, r8
beq foundverticaldown
foundverticaldown:
ldr r4, [r6,#24]
ldr r3, [r6,#8]
b loopoffoundverticaldown
loopoffoundverticaldown:
ldr r0, [r6,#64]
cmp r0, #1
beq skipendvalidverticaldown
sub r4, r4, #8
cmp r3, r4
beq endvalidverticaldown
strb r8, [r9,r4]
b loopoffoundverticaldown
notvalidverticaldown:
mov r4,#0
str r4, [r6, #44]
b endverticaldown
endvalidverticaldown:
str r4, [r6, #24]
ldr r4, [r6,#8]
strb r8, [r9,r4]
skipendvalidverticaldown:
mov r4,#1
str r4, [r6,#44]
b endverticaldown
forwardup:
mov r0, #1
ldr r4, [r6,#4]
cmp r0,r4
bge notvalidforwardup
mov r0,#6
ldr r4, [r6]
cmp r0,r4
ble notvalidforwardup
ldr r0, [r6]
add r0,r0,#1
str r0, [r6,#16]
ldr r0, [r6,#4]
sub r0,r0,#1
str r0, [r6,#20]
ldr r4, [r6,#8]
sub r4,r4,#7
str r4, [r6,#24]
ldrb r0, [r9,r4]
cmp r0, r5
beq loopforwardup
b notvalidforwardup
loopforwardup:
ldr r4, [r6,#24]
sub r4, r4, #7
str r4, [r6,#24]
ldr r4, [r6,#16]
add r4,r4,#1
str r4, [r6,#16]
ldr r4, [r6,#20]
sub r4,r4,#1
str r4, [r6,#20]
ldr r4, [r6,#16]
mov r0,#8
cmp r0,r4
beq notvalidforwardup
ldr r4, [r6,#20]
mov r0, #-1
cmp r0, r4
beq notvalidforwardup
ldr r4, [r6,#24]
ldrb r0, [r9,r4]
mov r1, #0
cmp r1, r0
beq notvalidforwardup
cmp r0, r5
beq loopforwardup
cmp r0, r8
beq foundforwardup
foundforwardup:
ldr r0, [r6,#64]
cmp r0, #1
beq skipendvalidfoundforwardup
ldr r4, [r6,#24]
ldr r3, [r6,#8]
b loopoffoundforwardup
loopoffoundforwardup:
add r4, r4, #7
cmp r3,r4
beq endvalidforwardup
strb r8, [r9,r4]
b loopoffoundforwardup
notvalidforwardup:
mov r4, #0
str r4, [r6,#48]
b endforwardup
endvalidforwardup:
ldr r4, [r6,#8]
strb r8, [r9,r4]
skipendvalidfoundforwardup:
mov r4, #1
str r4, [r6,#48]
b endforwardup
forwarddown:
mov r0, #6
ldr r4, [r6,#4]
cmp r0, r4
ble notvalidforwarddown
mov r0, #1
ldr r4, [r6]
cmp r0, r4
bge notvalidforwarddown
ldr r0, [r6]
sub r0, r0, #1
str r0, [r6,#16]
ldr r0, [r6,#4]
add r0, r0,#1
str r0, [r6,#20]
ldr r4, [r6, #8]
add r4, r4, #7
str r4, [r6,#24]
ldrb r0, [r9,r4]
cmp r0, r5
beq loopforwarddown
b notvalidforwarddown
loopforwarddown:
ldr r4, [r6,#24]
add r4, r4, #7
str r4, [r6,#24]
ldr r4, [r6,#16]
sub r4,r4,#1
str r4, [r6,#16]
ldr r4, [r6,#20]
add r4,r4,#1
str r4, [r6,#20]
ldr r4, [r6,#16]
mov r0,#-1
cmp r0, r4
beq notvalidforwarddown
ldr r4, [r6,#20]
mov r0, #8
cmp r0, r4
beq notvalidforwarddown
ldr r4, [r6,#24]
ldrb r0, [r9,r4]
mov r1, #0
cmp r1, r0
beq notvalidforwarddown
cmp r0, r5
beq loopforwarddown
cmp r0, r8
beq foundforwarddown
foundforwarddown:
ldr r0, [r6,#64]
cmp r0, #1
beq skipendvalidforwarddown
ldr r4, [r6,#24]
ldr r3, [r6,#8]
b loopoffoundforwarddown
loopoffoundforwarddown:
sub r4, r4, #7
cmp r3,r4
beq endvalidforwarddown
strb r8, [r9,r4]
b loopoffoundforwarddown
notvalidforwarddown:
mov r4, #0
str r4, [r6,#52]
b endforwarddown
endvalidforwarddown:
ldr r4, [r6,#8]
strb r8, [r9,r4]
skipendvalidforwarddown:
mov r4, #1
str r4, [r6,#52]
b endforwarddown
backup:
mov r0,#1
ldr r4, [r6]
cmp r0, r4
bge notvalidbackup
ldr r4, [r6,#4]
cmp r0, r4
bge notvalidbackup
ldr r0, [r6]
sub r0, r0, #1
str r0, [r6, #16]
ldr r0, [r6,#4]
sub r0, r0,#1
str r0, [r6,#20]
ldr r4, [r6, #8]
sub r4, r4, #9
str r4, [r6, #24]
ldrb r0, [r9,r4]
cmp r0, r5
beq loopbackup
b notvalidbackup
loopbackup:
ldr r4, [r6,#24]
sub r4, r4, #9
str r4, [r6,#24]
ldr r4, [r6,#16]
sub r4,r4,#1
str r4, [r6,#16]
ldr r4, [r6,#20]
sub r4,r4,#1
str r4, [r6,#20]
ldr r4, [r6,#16]
mov r0,#-1
cmp r0,r4
beq notvalidbackup
ldr r4, [r6,#20]
cmp r0, r4
beq notvalidbackup
ldr r4, [r6,#24]
ldrb r0, [r9,r4]
mov r1, #0
cmp r1, r0
beq notvalidbackup
cmp r0, r5
beq loopbackup
cmp r0, r8
beq foundbackup
foundbackup:
ldr r0, [r6,#64]
cmp r0, #1
beq skipendvalidfoundbackup
ldr r4, [r6,#24]
ldr r3, [r6,#8]
b loopoffoundbackup
loopoffoundbackup:
add r4, r4, #9
cmp r3,r4
beq endvalidbackup
strb r8, [r9,r4]
b loopoffoundbackup
notvalidbackup:
mov r4, #0
str r4, [r6,#56]
b endbackup
endvalidbackup:
ldr r4, [r6,#8]
strb r8, [r9,r4]
skipendvalidfoundbackup:
mov r4, #1
str r4, [r6,#56]
b endbackup
backdown:
mov r0,#6
ldr r4, [r6]
cmp r0, r4
ble notvalidbackdown
ldr r4, [r6,#4]
cmp r0, r4
ble notvalidbackdown
ldr r0, [r6]
add r0, r0, #1
str r0, [r6, #16]
ldr r0, [r6,#4]
add r0, r0,#1
str r0, [r6,#20]
ldr r4, [r6, #8]
add r4, r4, #9
str r4, [r6, #24]
ldrb r0, [r9,r4]
cmp r0, r5
beq loopbackdown
b notvalidbackdown
loopbackdown:
ldr r4, [r6,#24]
add r4, r4, #9
str r4, [r6,#24]
ldr r4, [r6,#16]
add r4,r4,#1
str r4, [r6,#16]
ldr r4, [r6,#20]
add r4,r4,#1
str r4, [r6,#20]
ldr r4, [r6,#16]
mov r0,#8
cmp r0,r4
beq notvalidbackdown
ldr r4, [r6,#20]
cmp r0, r4
beq notvalidbackdown
ldr r4, [r6,#24]
ldrb r0, [r9,r4]
mov r1, #0
cmp r1, r0
beq notvalidbackdown
cmp r0, r5
beq loopbackdown
cmp r0, r8
beq foundbackdown
foundbackdown:
ldr r0, [r6,#64]
cmp r0, #1
beq skipendvalidfoundbackdown
ldr r4, [r6,#24]
ldr r3, [r6,#8]
b loopoffoundbackdown
loopoffoundbackdown:
sub r4, r4, #9
cmp r3,r4
beq endvalidbackdown
strb r8, [r9,r4]
b loopoffoundbackdown
notvalidbackdown:
mov r4, #0
str r4, [r6,#60]
b endbackdown
endvalidbackdown:
ldr r4, [r6,#8]
strb r8, [r9,r4]
skipendvalidfoundbackdown:
mov r4, #1
str r4, [r6,#60]
b endbackdown
invalidmove:
mov r4,#0
LDMFD sp!, {lr}
mov pc, lr
@b endgame
hasvalidmove:
mov r4,#1
LDMFD sp!,{lr}
mov pc,lr
computelogtwo:
@ STMFD sp! {r1}
mov r1,#0
loopcomputlogtwo:
mov r0,r0,LSR #1
cmp r0,#0
beq endcomputelogtwo
add r1,r1,#1
b loopcomputlogtwo
endcomputelogtwo:
@ LDMFD sp! {r1}
mov pc, lr
@ START OF ARRAY PRINTER FUNCTION------------------------------------
arrayprinter:
STMFD sp!, {r0-r3,r7,r9}
mov r0,#1
mov r1,#0
ldr r2,=Xindex
swi 0x204
mov r0,#0
mov r1,#1
mov r2,#0
swi 0x205
mov r3,#0
mov r0,#1
mov r1,#1
gotoprintloop:
ldrb r2, [r9,r3]
b getasci
outasci:
STMFD sp!, {r0}
mov r0, r0, LSL #1
swi 0x207
LDMFD sp!, {r0}
add r0,r0,#1
add r3, r3,#1
cmp r0,#9
beq changerow
b gotoprintloop
changerow:
add r1,r1,#1
mov r0,#1
cmp r1,#9
beq exitprinter
mov r0,#0
sub r2,r1,#1
swi 0x205
mov r0,#1
b gotoprintloop
exitprinter:
mov r0,#0
mov r1,#9
ldr r2,=ScoreString1
swi 0x204
mov r0,#22
ldr r2,[r7]
swi 0x205
mov r0,#0
mov r1,#10
ldr r2,=ScoreString2
swi 0x204
mov r0, #22
ldr r2,[r7,#4]
swi 0x205
LDMFD sp!, {r0-r3,r7,r9}
mov pc, lr
getasci:
cmp r2, #0
moveq r2, #'.
beq outasci
cmp r2, #1
moveq r2, #'W
beq outasci
cmp r2, #2
moveq r2, #'B
beq outasci
@ END OF ARRAYPRINTER FUNCTION-------------------
@ START OF initialize FUNCTION---------------
initialize:
STMFD sp!,{r0-r1}
ldr r9,=Array
mov r0,#0
mov r1,#0
loopofinitialize:
strb r0, [r9,r1]
add r1,r1,#1
cmp r1,#64
beq endofinitialize
b loopofinitialize
endofinitialize:
mov r0,#1
strb r0, [r9,#27]
strb r0, [r9,#36]