|
3 | 3 | .text
|
4 | 4 | # User Input Section
|
5 | 5 | UserInput:
|
| 6 | + jal OptionDisplay |
6 | 7 | # Prompt user for the 1st coordinate
|
7 | 8 | li $v0, 4 # print string syscall
|
8 | 9 | la $a0, prompt1 # load 1st prompt message
|
|
28 | 29 | sub $t7, $t7, 1 # row starts from 0
|
29 | 30 | mul $t7, $t7, 4 # row * 4 to get row index offset
|
30 | 31 | add $t7, $t7, $t6 # final index = row index + column index
|
| 32 | + add $a1, $t7, $zero # store the index number into a temp variable for use in the display code |
31 | 33 | mul $t7, $t7, 4 # convert index to byte offset (word = 4 bytes)
|
32 | 34 |
|
33 | 35 | # Load the value from the key array at 1st coordinate
|
|
61 | 63 |
|
62 | 64 | li $v0, 5 # read integer syscall (row)
|
63 | 65 | syscall
|
64 |
| - move $t7, $v0 # store integer (row) into $t7 |
| 66 | + move $t2, $v0 # store integer (row) into $t7 |
65 | 67 |
|
66 | 68 | # Convert coordinates into an index
|
67 | 69 | li $t9, 'A'
|
68 | 70 | sub $t6, $t6, $t9 # convert char A-D to 0-3
|
69 | 71 |
|
70 | 72 | blt $t6, 0, invalid_input # check for invalid input (column out of range)
|
71 | 73 | bgt $t6, 3, invalid_input # check for invalid input (column out of range)
|
72 |
| - blt $t7, 1, invalid_input # check for invalid input (row out of range) |
73 |
| - bgt $t7, 4, invalid_input # check for invalid input (row out of range) |
| 74 | + blt $t2, 1, invalid_input # check for invalid input (row out of range) |
| 75 | + bgt $t2, 4, invalid_input # check for invalid input (row out of range) |
74 | 76 |
|
75 |
| - sub $t7, $t7, 1 # row starts from 0 |
76 |
| - mul $t7, $t7, 4 # row * 4 to get row index offset |
77 |
| - add $t7, $t7, $t6 # final index = row index + column index |
78 |
| - mul $t7, $t7, 4 # convert index to byte offset (word = 4 bytes) |
| 77 | + sub $t2, $t2, 1 # row starts from 0 |
| 78 | + mul $t2, $t2, 4 # row * 4 to get row index offset |
| 79 | + add $t2, $t2, $t6 # final index = row index + column index |
| 80 | + add $a2, $t2, $zero # store the index number into a temp variable for use in the display code |
| 81 | + mul $t2, $t2, 4 # convert index to byte offset (word = 4 bytes) |
79 | 82 |
|
80 | 83 | # Load the value from the key array at 2nd coordinate
|
81 | 84 | la $t1, randKeyArray
|
82 |
| - add $t1, $t1, $t7 # calculate address |
| 85 | + add $t1, $t1, $t2 # calculate address |
83 | 86 | lw $t9, 0($t1) # load value
|
84 | 87 |
|
85 |
| - # Load and print the value from the content array at 2nd coordinate |
| 88 | + # Load and print the value from the content array at 1st coordinate |
86 | 89 | la $t1, randContentArray
|
87 |
| - add $t1, $t1, $t7 # Calculate address |
88 |
| - li $v0, 4 # print string syscall |
| 90 | + add $t1, $t1, $t2 # Calculate address |
| 91 | + li $v0, 4 # print string syscall |
89 | 92 | la $a0, value_message # load "The value at this coordinate is: "
|
90 | 93 | syscall
|
91 | 94 |
|
92 | 95 | li $v0, 4 # print integer syscall
|
93 |
| - la $a0, 0($t1) # move the value to $a0 |
| 96 | + la $a0, 0($t1) # move the value to $a0 |
94 | 97 | syscall
|
95 | 98 |
|
96 | 99 | li $v0, 4 # print string syscall for newline
|
|
106 | 109 | b UserInput # repeat the input process
|
107 | 110 |
|
108 | 111 | match_found:
|
| 112 | + li $a3, -1 |
| 113 | + la $t1, randKeyArray |
| 114 | + add $t1, $t1, $t7 |
| 115 | + sw $a3, 0($t1) |
| 116 | + la $t1, randKeyArray |
| 117 | + add $t1, $t1, $t2 |
| 118 | + sw $a3, 0($t1) |
109 | 119 | li $v0, 4 # print string syscall
|
110 | 120 | la $a0, match # load "It's a match!" message
|
111 | 121 | syscall
|
112 | 122 |
|
113 | 123 | # Play match sound
|
114 | 124 | jal MatchSound
|
115 | 125 |
|
116 |
| - lw $t9, numMatches # Load the current match count |
117 |
| - addi $t9, $t9, 1 # Increment match counter |
118 |
| - sw $t9, numMatches # Store updated match count |
| 126 | + lw $t0, numMatches # Load the current match count |
| 127 | + addi $t0, $t0, 1 # Increment match counter |
| 128 | + sw $t0, numMatches # Store updated match count |
119 | 129 |
|
120 | 130 | # Print the number of matches found so far
|
121 | 131 | li $v0, 4 # print string syscall
|
122 | 132 | la $a0, match_count_message # load "Number of matches: " message
|
123 | 133 | syscall
|
124 | 134 |
|
125 | 135 | li $v0, 1 # print integer syscall
|
126 |
| - move $a0, $t9 # move the match count to $a0 |
| 136 | + move $a0, $t0 # move the match count to $a0 |
127 | 137 | syscall
|
128 | 138 |
|
129 | 139 | li $v0, 4 # print string syscall for newline
|
130 | 140 | la $a0, newline # load newline
|
131 | 141 | syscall
|
132 | 142 |
|
133 | 143 | # Check if 8 matches are found
|
134 |
| - li $t8, 8 |
135 |
| - bne $t9, $t8, UserInput # If less than 8 matches, continue |
| 144 | + bne $t0, 8, UserInput # If less than 8 matches, continue |
136 | 145 |
|
137 | 146 | # If 8 matches are made, go to EndGame
|
138 | 147 | jal EndGame
|
|
0 commit comments