-
Notifications
You must be signed in to change notification settings - Fork 0
/
checker.asm
176 lines (154 loc) · 4.82 KB
/
checker.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
################### Checker for whether the game is over ###################
# Overall Program Functional Description:
#This function is meant to check whether a player 1 or player 2 has won the game
#or neither has won the game.
#returns -1 if player has 4 in a row,
#0 if no 4 in a row, or 1 if computer has 4 in a row
################################################################
# Register Usage in Main:
#$a0: used to pass the address of an array to the function
#$a1: used to pass the length parameter “N” to the function
################################################################
# Pseudocode Description:
#Check topleft 3x4 for 4 in a row (Diagonally to the right)
#Check topright 3x4 for 4 in a row (Diagonally to the left)
#Check horizontals for a 4 in a row
#Check verticals for a 4 in a row
#if no 4 in a row, return 0
#################################################################
.data
#board: .word 168
.align 2
#test cases
#empty board
#0,0,0,0,0,0,0
#0,0,0,0,0,0,0
#0,0,0,0,0,0,0
#0,0,0,0,0,0,0
#0,0,0,0,0,0,0
#0,0,0,0,0,0,0
#board: .word 0,0,0,0,0,0,0 0,0,0,0,0,0,0 0,0,0,0,0,0,0 0,0,0,0,0,0,0 0,0,0,0,0,0,0 0,0,0,0,0,0,0
#human win
#1,0,0,0,0,0,0
#0,1,0,0,0,0,0
#0,0,1,0,0,0,0
#0,0,0,1,0,0,0
#0,0,0,0,0,0,0
#0,0,0,0,0,0,0
#board: .word 1,0,0,0,0,0,0 0,1,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,0,1,0
#0,0,0,0,0,-1,0
#0,0,0,1,1,0,0
#0,0,1,1,0,0,0
#0,0,1,0,0,0,0
#0,1,0,0,0,0,0
#board: .word 0,0,0,0,0,1,0 0,0,0,0,0,-1,0 0,0,0,1,1,0,0 0,0,1,1,0,0,0 0,0,1,0,0,0,0 0,1,0,0,0,0,0
#0,0,0,0,0,1,0
#0,0,0,0,0,-1,0
#0,0,0,1,1,-1,0
#0,0,1,0,-1,0,0
#0,0,1,-1,0,0,0
#0,1,-1,0,0,0,0
#board: .word 0,0,0,0,0,1,0 0,0,0,0,0,-1,0 0,0,0,1,1,-1,0 0,0,1,0,-1,0,0 0,0,1,-1,0,0,0 0,1,-1,0,0,0,0
#horizontal
#human win
#0,1,0,1,1,0,0
#0,0,0,0,0,0,0
#0,0,0,0,0,0,0
#0,0,1,1,1,1,0
#0,0,0,0,0,0,0
#0,0,0,0,0,0,0
#board: .word 0,1,0,1,1,0,0 0,0,0,0,0,0,0 0,0,0,0,0,0,0 0,0,1,1,1,1,0 0,0,0,0,0,0,0 0,0,0,0,0,0,0
#vertical
#human win
#0,0,-1,0,0,0,0
#0,0,-1,0,0,0,0
#0,0,-1,0,0,0,0
#0,0,-1,0,0,0,0
#0,0,0,0,0,0,0
#0,0,0,0,0,0,0
#board: .word 0,0,-1,0,0,0,0 0,0,-1,0,0,0,0 0,0,-1,0,0,0,0 0,0,-1,0,0,0,0 0,0,0,0,0,0,0 0,0,0,0,0,0,0
#human win
#0,0,0,0,0,0,0
#0,0,0,0,1,0,0
#0,0,1,0,1,0,0
#0,0,1,0,1,0,0
#0,0,0,0,1,0,0
#0,0,1,0,0,0,0
#board: .word 0,0,0,0,0,0,0 0,0,0,0,1,0,0 0,0,1,0,1,0,0 0,0,1,0,1,0,0 0,0,0,0,1,0,0 0,0,1,0,0,0,0
.text
.globl checker
# .globl board
# .globl main
# main:
checker:
#store return address on stack
addiu $sp, $sp, -4
sw $ra, 0($sp)
addiu $sp, $sp, -4
jal check_top_left # jump to check_top_left and save position to $ra
lw $v0, 0($sp)
addiu $sp, $sp, 4
bne $v0, $zero, end # if $t0 != $t1 then target
addiu $sp, $sp, -4
jal check_top_right # jump to check_top_right and save position to $ra
lw $v0, 0($sp)
addiu $sp, $sp, 4
bne $v0, $zero, end # if $t0 != $t1 then target
addiu $sp, $sp, -4
jal check_horizontal # jump to check_horizontal and save position to $ra
lw $v0, 0($sp)
addiu $sp, $sp, 4
bne $v0, $zero, end # if $t0 != $t1 then target
addiu $sp, $sp, -4
jal check_vertical # jump to check_vertical and save position to $ra
lw $v0, 0($sp)
addiu $sp, $sp, 4
bne $v0, $zero, end # if $t0 != $t1 then target
end:
# li $v0,10
# syscall
#restore return address from stack
lw $ra, 0($sp) #
addiu $sp, $sp, 4
jr $ra