-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReversi.asm
100 lines (77 loc) · 1.78 KB
/
Reversi.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
# The entrypoint of the Reversi Game
# we will be building for our Computer
# Architecture class
.text
.globl main
main:
#input: Get the users menu choice
jal getMainMenu
beq $v0, 2, end_application
#method: Begin running the application
jal runApplication
#method: Check if player wants to play again
jal playAgain
beq $v0, 2, end_application
j main
end_application:
#method: End the application
li $v0, 10
syscall
runApplication:
#method: Save the return address
move $a0, $ra
jal saveReturnAdd
#method: Place the initial pieces for the game
jal placeInitialPieces
begin_turn:
#output: Render the gameboard
jal displayGameboard
#input: Get the validated input for the user's move this turn
jal getUserInput
#method: Extract the row data
srl $t0, $v0, 4
#method: Extract the column data
andi $t1, $v0, 0xf
#method: Place the user's piece on the board
li $a0, 88
move $a1, $t0
move $a2, $t1
jal placePiece
#output: Render the gameboard
jal displayGameboard
#method: The computer takes its turn
jal computerTurn
#method: Check if there are valid moves remaining for the user
jal validMovesRemaining
#method: If there are valid moves remaining, continue the game
bnez $v0, begin_turn
#method: Load the return address
jal loadReturnAdd
jr $ra
placeInitialPieces:
#method: Save the return address
move $a0, $ra
jal saveReturnAdd
#method: Place the first X
li $a0, 88
li $a1, 3
li $a2, 3
jal writeBoardPosition
#method: Place the second X
li $a0, 88
li $a1, 4
li $a2, 4
jal writeBoardPosition
#method: Place the first O
li $a0, 79
li $a1, 3
li $a2, 4
jal writeBoardPosition
#method: Place the second O
li $a0, 79
li $a1, 4
li $a2, 3
jal writeBoardPosition
#method: Load the return address
jal loadReturnAdd
jr $ra