summaryrefslogtreecommitdiff
path: root/tests/examplefiles/mips/function_with_stack.mips.output
blob: 552b93601b47d96600840a22a75ee1d79f7aa414 (plain)
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
'# Simple routine to demo functions' Comment
'\n'          Text.Whitespace

'# USING a stack in this example to preserve' Comment
'\n'          Text.Whitespace

'# values of calling function' Comment
'\n\n'        Text.Whitespace

'# ------------------------------------------------------------------' Comment
'\n\n    '    Text.Whitespace
'.text'       Name.Entity
'\n\n    '    Text.Whitespace
'.globl'      Name.Entity
'  '          Text.Whitespace
'main'        Text
'\n'          Text.Whitespace

'main:'       Name.Function
'\n    '      Text.Whitespace
'# Register assignments' Comment
'\n    '      Text.Whitespace
'# $s0 = x'   Comment
'\n    '      Text.Whitespace
'# $s1 = y'   Comment
'\n\n    '    Text.Whitespace
'# Initialize registers' Comment
'\n    '      Text.Whitespace
'lw'          Keyword
'  '          Text.Whitespace
'$s0'         Keyword.Type
','           Name.Builtin
' '           Text.Whitespace
'x'           Text
'      '      Text.Whitespace
'# Reg $s0 = x' Comment
'\n    '      Text.Whitespace
'lw'          Keyword
'  '          Text.Whitespace
'$s1'         Keyword.Type
','           Name.Builtin
' '           Text.Whitespace
'y'           Text
'      '      Text.Whitespace
'# Reg $s1 = y' Comment
'\n\n    '    Text.Whitespace
'# Call function' Comment
'\n    '      Text.Whitespace
'move'        Name.Variable
'    '        Text.Whitespace
'$a0'         Keyword.Type
','           Name.Builtin
' '           Text.Whitespace
'$s0'         Keyword.Type
'    '        Text.Whitespace
'# Argument 1: x ($s0)' Comment
'\n    '      Text.Whitespace
'jal'         Keyword
' '           Text.Whitespace
'fun'         Text
'     '       Text.Whitespace
'# Save current PC in $ra, and jump to fun' Comment
'\n    '      Text.Whitespace
'move'        Name.Variable
'    '        Text.Whitespace
'$s1'         Keyword.Type
','           Name.Builtin
'$v0'         Keyword.Type
'     '       Text.Whitespace
'# Return value saved in $v0. This is y ($s1)' Comment
'\n\n    '    Text.Whitespace
'# Print msg1' Comment
'\n    '      Text.Whitespace
'li'          Name.Variable
'  '          Text.Whitespace
'$v0'         Keyword.Type
','           Name.Builtin
' '           Text.Whitespace
'4'           Keyword.Constant
'      '      Text.Whitespace
'# print_string syscall code = 4' Comment
'\n    '      Text.Whitespace
'la'          Name.Variable
'  '          Text.Whitespace
'$a0'         Keyword.Type
','           Name.Builtin
' '           Text.Whitespace
'msg1'        Text
'\n    '      Text.Whitespace
'syscall'     Keyword
'\n\n    '    Text.Whitespace
'# Print result (y)' Comment
'\n    '      Text.Whitespace
'li'          Name.Variable
'  '          Text.Whitespace
'$v0'         Keyword.Type
','           Name.Builtin
'1'           Keyword.Constant
'       '     Text.Whitespace
'# print_int syscall code = 1' Comment
'\n    '      Text.Whitespace
'move'        Name.Variable
'    '        Text.Whitespace
'$a0'         Keyword.Type
','           Name.Builtin
' '           Text.Whitespace
'$s1'         Keyword.Type
'    '        Text.Whitespace
'# Load integer to print in $a0' Comment
'\n    '      Text.Whitespace
'syscall'     Keyword
'\n\n    '    Text.Whitespace
'# Print newline' Comment
'\n    '      Text.Whitespace
'li'          Name.Variable
'  '          Text.Whitespace
'$v0'         Keyword.Type
','           Name.Builtin
'4'           Keyword.Constant
'       '     Text.Whitespace
'# print_string syscall code = 4' Comment
'\n    '      Text.Whitespace
'la'          Name.Variable
'  '          Text.Whitespace
'$a0'         Keyword.Type
','           Name.Builtin
' '           Text.Whitespace
'lf'          Text
'\n    '      Text.Whitespace
'syscall'     Keyword
'\n\n    '    Text.Whitespace
'# Exit'      Comment
'\n    '      Text.Whitespace
'li'          Name.Variable
'  '          Text.Whitespace
'$v0'         Keyword.Type
','           Name.Builtin
'1'           Keyword.Constant
'0'           Keyword.Constant
'      '      Text.Whitespace
'# exit'      Comment
'\n    '      Text.Whitespace
'syscall'     Keyword
'\n\n'        Text.Whitespace

'# ------------------------------------------------------------------' Comment
'\n\n    '    Text.Whitespace
'# FUNCTION: int fun(int a)' Comment
'\n    '      Text.Whitespace
'# Arguments are stored in $a0' Comment
'\n    '      Text.Whitespace
'# Return value is stored in $v0' Comment
'\n    '      Text.Whitespace
'# Return address is stored in $ra (put there by jal instruction)' Comment
'\n    '      Text.Whitespace
'# Typical function operation is:' Comment
'\n\n'        Text.Whitespace

'fun:'        Name.Function
'    '        Text.Whitespace
'# This function overwrites $s0 and $s1' Comment
'\n    '      Text.Whitespace
'# We should save those on the stack' Comment
'\n    '      Text.Whitespace
"# This is PUSH'ing onto the stack" Comment
'\n    '      Text.Whitespace
'addi'        Keyword
' '           Text.Whitespace
'$sp'         Keyword.Type
','           Name.Builtin
'$sp'         Keyword.Type
','           Name.Builtin
'-4'          Keyword.Constant
'     '       Text.Whitespace
'# Adjust stack pointer' Comment
'\n    '      Text.Whitespace
'sw'          Keyword
' '           Text.Whitespace
'$s0'         Keyword.Type
','           Name.Builtin
'0'           Keyword.Constant
'('           Text
'$sp'         Keyword.Type
')'           Text
'       '     Text.Whitespace
'# Save $s0'  Comment
'\n    '      Text.Whitespace
'addi'        Keyword
' '           Text.Whitespace
'$sp'         Keyword.Type
','           Name.Builtin
'$sp'         Keyword.Type
','           Name.Builtin
'-4'          Keyword.Constant
'     '       Text.Whitespace
'# Adjust stack pointer' Comment
'\n    '      Text.Whitespace
'sw'          Keyword
' '           Text.Whitespace
'$s1'         Keyword.Type
','           Name.Builtin
'0'           Keyword.Constant
'('           Text
'$sp'         Keyword.Type
')'           Text
'       '     Text.Whitespace
'# Save $s1'  Comment
'\n\n    '    Text.Whitespace
'# Do the function math' Comment
'\n    '      Text.Whitespace
'li'          Name.Variable
' '           Text.Whitespace
'$s0'         Keyword.Type
','           Name.Builtin
' '           Text.Whitespace
'3'           Keyword.Constant
'\n    '      Text.Whitespace
'mul'         Keyword
' '           Text.Whitespace
'$s1'         Keyword.Type
','           Name.Builtin
'$s0'         Keyword.Type
','           Name.Builtin
'$a0'         Keyword.Type
'     '       Text.Whitespace
'# s1 = 3*$a0  (i.e. 3*a)' Comment
'\n    '      Text.Whitespace
'addi'        Keyword
' '           Text.Whitespace
'$s1'         Keyword.Type
','           Name.Builtin
'$s1'         Keyword.Type
','           Name.Builtin
'5'           Keyword.Constant
'      '      Text.Whitespace
'# 3*a+5'     Comment
'\n\n    '    Text.Whitespace
'# Save the return value in $v0' Comment
'\n    '      Text.Whitespace
'move'        Name.Variable
' '           Text.Whitespace
'$v0'         Keyword.Type
','           Name.Builtin
'$s1'         Keyword.Type
'\n\n    '    Text.Whitespace
'# Restore saved register values from stack in opposite order' Comment
'\n    '      Text.Whitespace
"# This is POP'ing from the stack" Comment
'\n    '      Text.Whitespace
'lw'          Keyword
' '           Text.Whitespace
'$s1'         Keyword.Type
','           Name.Builtin
'0'           Keyword.Constant
'('           Text
'$sp'         Keyword.Type
')'           Text
'       '     Text.Whitespace
'# Restore $s1' Comment
'\n    '      Text.Whitespace
'addi'        Keyword
' '           Text.Whitespace
'$sp'         Keyword.Type
','           Name.Builtin
'$sp'         Keyword.Type
','           Name.Builtin
'4'           Keyword.Constant
'      '      Text.Whitespace
'# Adjust stack pointer' Comment
'\n    '      Text.Whitespace
'lw'          Keyword
' '           Text.Whitespace
'$s0'         Keyword.Type
','           Name.Builtin
'0'           Keyword.Constant
'('           Text
'$sp'         Keyword.Type
')'           Text
'       '     Text.Whitespace
'# Restore $s0' Comment
'\n    '      Text.Whitespace
'addi'        Keyword
' '           Text.Whitespace
'$sp'         Keyword.Type
','           Name.Builtin
'$sp'         Keyword.Type
','           Name.Builtin
'4'           Keyword.Constant
'      '      Text.Whitespace
'# Adjust stack pointer' Comment
'\n\n    '    Text.Whitespace
'# Return from function' Comment
'\n    '      Text.Whitespace
'jr'          Keyword
' '           Text.Whitespace
'$ra'         Keyword.Type
'          '  Text.Whitespace
'# Jump to addr stored in $ra' Comment
'\n\n'        Text.Whitespace

'# ------------------------------------------------------------------' Comment
'\n\n    '    Text.Whitespace
'# Start .data segment (data!)' Comment
'\n    '      Text.Whitespace
'.data'       Name.Entity
'\n'          Text.Whitespace

'x:'          Name.Function
'  '          Text.Whitespace
'.word'       Name.Entity
' '           Text.Whitespace
'5'           Keyword.Constant
'\n'          Text.Whitespace

'y:'          Name.Function
'  '          Text.Whitespace
'.word'       Name.Entity
' '           Text.Whitespace
'0'           Keyword.Constant
'\n'          Text.Whitespace

'msg1:'       Name.Function
'   '         Text.Whitespace
'.asciiz'     Name.Entity
' '           Text.Whitespace
'"'           Literal.String
'y='          Literal.String
'"'           Literal.String
'\n'          Text.Whitespace

'lf:'         Name.Function
'     '       Text.Whitespace
'.asciiz'     Name.Entity
' '           Text.Whitespace
'"'           Literal.String
'\\n'         Literal.String.Escape
'"'           Literal.String
'\n'          Text.Whitespace