-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoreOutput.asm
201 lines (155 loc) · 4.02 KB
/
CoreOutput.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
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
# This file contains the core
# output manipulation & formatting
# subroutines utilized in the
# Reversi application
.data
str_newLine: .asciiz "\n"
str_whitespace: .asciiz " "
str_promptDelim: .asciiz "-"
str_errorDelim: .asciiz "*"
str_noticeDelim: .asciiz "="
str_errorTitle: .asciiz "ERROR"
str_noticeTitle: .asciiz "NOTICE"
delimWidth: .word 10
ptr_a0: .word 0
ptr_a1: .word 0
ptr_a2: .word 0
ptr_a3: .word 0
.text
.globl renderTitle
renderTitle:
#method: Move arguments into memory
# $a0 : title address
# $a1 : subtitle address
# $a2 : delimiter address
sw $a0, ptr_a0
sw $a1, ptr_a1
sw $a2, ptr_a2
#method: Save registers to the stack
move $a0, $ra
jal saveAllRegisters
#method: Pull arguments out of memory
lw $s0, ptr_a0
lw $s1, ptr_a1
lw $s2, ptr_a2
#method: Print newline
la $a0, str_newLine
li $v0, 4
syscall
#method: Move the delimiter into $a0 and call printDelimiter
move $a0, $s2
jal printDelimiter
#output: Print the str_whitespace between delimiter and title
la $a0, str_whitespace
li $v0, 4
syscall
#output: Print the title
move $a0, $s0
li $v0, 4
syscall
#output: Print the str_whitespace between delimiter and title
la $a0, str_whitespace
li $v0, 4
syscall
#method: Move the delimiter into $a0 and call printDelimiter
move $a0, $s2
jal printDelimiter
#output: Print newline
la $a0, str_newLine
li $v0, 4
syscall
#output: Print subtitle
move $a0, $s1
li $v0, 4
syscall
#method: Load registers from the stack
jal loadAllRegisters
jr $ra
.globl renderPrompt
renderPrompt:
#method: Move arguments into memory
# $a0 : title address
# $a1 : subtitle address
# $a2 : delimiter address
# $a3 : string buffer
sw $a0, ptr_a0
sw $a1, ptr_a1
#method: Save registers to the stack
move $a0, $ra
jal saveAllRegisters
#method: Pull arguments out of memory
lw $a0, ptr_a0
lw $a1, ptr_a1
#method: Set the delimiter to '-'
la $a2, str_promptDelim
#output: Print the prompt
jal renderTitle
#method: Load registers from the stack
jal loadAllRegisters
jr $ra
.text
.globl renderError
renderError:
#method: Move arguments into memory
# $a0 : subtitle address
sw $a0, ptr_a0
#method: Save registers to the stack
move $a0, $ra
jal saveAllRegisters
#method: Pull arguments out of memory
lw $a1, ptr_a0
#method: Set the title to "ERROR" and the delimiter to "*"
la $a0, str_errorTitle
la $a2, str_errorDelim
#output: Print the error
jal renderTitle
#method: Load registers from the stack
jal loadAllRegisters
jr $ra
.globl renderNotice
renderNotice:
#method: Move arguments into memory
# $a0 : subtitle address
sw $a0, ptr_a0
#method: Save registers to the stack
move $a0, $ra
jal saveAllRegisters
#method: Pull arguments out of memory
lw $a1, ptr_a0
#method: Set the title to "NOTICE" and the delimiter to "="
la $a0, str_noticeTitle
la $a2, str_noticeDelim
#output: Print the error
jal renderTitle
#method: Load registers from the stack
jal loadAllRegisters
jr $ra
# Print the delimieter stored in $a0 10 times
printDelimiter:
# $t0 : total times to print
# $t1 : loop counter
# $v0 : syscall to print string
lw $t0, delimWidth
li $t1, 0
li $v0, 4
print_delim:
#condition: if done printing, exit loop
beq $t0, $t1, print_delim_complete
#output: Print the delimiter
syscall
#method: add 1 to the counter
addi $t1, $t1, 1
j print_delim
print_delim_complete:
jr $ra
.globl clearScreen
#method: Display 40 new lines before each launch to clear the screen
clearScreen:
#method: Print the newline character
la $a0, str_newLine
li $v0, 4
syscall
#conditon: If 40 newlines haven't been printed yet, continue looping.
addi $a3, $a3, 1
bne $a3, 40, clearScreen
jr $ra