Skip to content

Commit 580bc54

Browse files
authored
Merge pull request #10 from srana3/jDeHoyos10_28
started implementing the display
2 parents 1771fd8 + 93103d7 commit 580bc54

File tree

3 files changed

+154
-21
lines changed

3 files changed

+154
-21
lines changed

CS 2340/Project Files/display.asm

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
.globl OptionDisplay
2+
.globl SelectionDisplay
3+
4+
.text
5+
OptionDisplay:
6+
li $t0, 0 # counter for the number of lines we have printed
7+
li $t1, 0 # counter for the number of cells we have printed
8+
la $t4, randKeyArray
9+
Print:
10+
bgtz $t0, StartCell # if it's not the first line, print the cells
11+
12+
li $v0, 4
13+
la $a0, colNames # print out the label for the columns
14+
syscall
15+
16+
add $t0, $t0, 1 # increment lines printed by 1
17+
18+
StartCell:
19+
li $v0, 1
20+
add $a0, $t0, $zero
21+
syscall
22+
23+
PrintCells:
24+
li $v0, 4
25+
lw $t5, ($t4)
26+
bltz $t5, PrintKnown
27+
28+
la $a0, unknown
29+
syscall
30+
j NextCell
31+
32+
PrintKnown:
33+
la $a0, known
34+
syscall
35+
36+
NextCell:
37+
add $t1, $t1, 1 # increment cells count by 1
38+
add $t4, $t4, 4
39+
blt $t1, 4, PrintCells # if we haven't printed 4 cells in a row yet, print another cell
40+
41+
li $t1, 0
42+
la $a0, endCap
43+
syscall
44+
45+
add $t0, $t0, 1
46+
47+
beq $t0, 5, End
48+
49+
j Print
50+
51+
SelectionDisplay:
52+
li $t0, 0 # counter for the number of lines we have printed
53+
li $t1, 0 # counter for the number of cells we have printed
54+
la $t4, randKeyArray
55+
56+
Print2:
57+
bgtz $t0, StartCell2 # if it's not the first line, print the cells
58+
59+
li $v0, 4
60+
la $a0, colNames # print out the label for the columns
61+
syscall
62+
63+
add $t0, $t0, 1 # increment lines printed by 1
64+
65+
StartCell2:
66+
li $v0, 1
67+
add $a0, $t0, $zero
68+
syscall
69+
70+
PrintCell2:
71+
li $v0, 4
72+
73+
CheckFirst:
74+
bne $t1, $a1, CheckSecond
75+
li $t6, 0
76+
la $t6, randContentArray
77+
add $t6, $t6, $t7
78+
la $a0, 0($t6)
79+
syscall
80+
j NextCell2
81+
82+
CheckSecond:
83+
bne $t1, $a2, Unselected
84+
la $t6, randContentArray
85+
add $t6, $t6, $t2
86+
la $a0, 0($t6)
87+
syscall
88+
j NextCell2
89+
90+
Unselected:
91+
lw $t5, ($t4)
92+
bltz $t5, PrintKnown2
93+
94+
la $a0, unknown
95+
syscall
96+
j NextCell2
97+
98+
PrintKnown2:
99+
la $a0, known
100+
syscall
101+
NextCell2:
102+
add $t1, $t1, 1 # increment cells count by 1
103+
rem $a3, $t1, 4
104+
add $t4, $t4, 4
105+
bnez $a3, PrintCell2 # if we haven't printed 4 cells in a row yet, print another cell
106+
la $a0, endCap
107+
syscall
108+
109+
add $t0, $t0, 1
110+
111+
beq $t0, 5, End
112+
113+
j Print2
114+
115+
End:
116+
jr $ra

CS 2340/Project Files/main.asm

+11-3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
.globl IntToString
2121
IntToString: .space 128 # bytes for the string version of contentArray
2222
.globl prompt1
23-
prompt1: .asciiz "\nEnter 1st coordinate (A-D, 1-4): "
23+
prompt1: .asciiz "Enter 1st coordinate (A-D, 1-4): "
2424
.globl prompt2
25-
prompt2: .asciiz "\nEnter 2nd coordinate (A-D, 1-4): "
25+
prompt2: .asciiz "Enter 2nd coordinate (A-D, 1-4): "
2626
.globl not_match
27-
not_match: .asciiz "\nNot a match!"
27+
not_match: .asciiz "\nNot a match!\n"
2828
.globl match
2929
match: .asciiz "\nIt's a match!"
3030
.globl invalid
@@ -37,6 +37,14 @@
3737
match_count_message: .asciiz "\nNumber of matches: "
3838
.globl newline
3939
newline: .asciiz "\n"
40+
.globl colNames
41+
colNames: .asciiz "\n A B C D \n"
42+
.globl unknown
43+
unknown: .asciiz "| ? "
44+
.globl known
45+
known: .asciiz "| "
46+
.globl endCap
47+
endCap: .asciiz "|\n"
4048

4149
.text
4250
StartGame:

CS 2340/Project Files/userInput.asm

+27-18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.text
44
# User Input Section
55
UserInput:
6+
jal OptionDisplay
67
# Prompt user for the 1st coordinate
78
li $v0, 4 # print string syscall
89
la $a0, prompt1 # load 1st prompt message
@@ -28,6 +29,7 @@
2829
sub $t7, $t7, 1 # row starts from 0
2930
mul $t7, $t7, 4 # row * 4 to get row index offset
3031
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
3133
mul $t7, $t7, 4 # convert index to byte offset (word = 4 bytes)
3234

3335
# Load the value from the key array at 1st coordinate
@@ -61,36 +63,37 @@
6163

6264
li $v0, 5 # read integer syscall (row)
6365
syscall
64-
move $t7, $v0 # store integer (row) into $t7
66+
move $t2, $v0 # store integer (row) into $t7
6567

6668
# Convert coordinates into an index
6769
li $t9, 'A'
6870
sub $t6, $t6, $t9 # convert char A-D to 0-3
6971

7072
blt $t6, 0, invalid_input # check for invalid input (column out of range)
7173
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)
7476

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)
7982

8083
# Load the value from the key array at 2nd coordinate
8184
la $t1, randKeyArray
82-
add $t1, $t1, $t7 # calculate address
85+
add $t1, $t1, $t2 # calculate address
8386
lw $t9, 0($t1) # load value
8487

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
8689
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
8992
la $a0, value_message # load "The value at this coordinate is: "
9093
syscall
9194

9295
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
9497
syscall
9598

9699
li $v0, 4 # print string syscall for newline
@@ -106,33 +109,39 @@
106109
b UserInput # repeat the input process
107110

108111
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)
109119
li $v0, 4 # print string syscall
110120
la $a0, match # load "It's a match!" message
111121
syscall
112122

113123
# Play match sound
114124
jal MatchSound
115125

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
119129

120130
# Print the number of matches found so far
121131
li $v0, 4 # print string syscall
122132
la $a0, match_count_message # load "Number of matches: " message
123133
syscall
124134

125135
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
127137
syscall
128138

129139
li $v0, 4 # print string syscall for newline
130140
la $a0, newline # load newline
131141
syscall
132142

133143
# 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
136145

137146
# If 8 matches are made, go to EndGame
138147
jal EndGame

0 commit comments

Comments
 (0)