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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
; ./clipboard - Test1.xx.xasm
; XieXie generated source file
; Wed Jun 11 21:22:21 2014
call Main
stop
; --- Procedure Definition "Faculty" ---
Faculty:
; If Statement
ldw i0, (lb) -4
xor i1, i1
push i1
push i0
call Intr.CmpE
pop i0
xor i1, i1
cmp i0, i1
je .else_0
push 1
ret (1) 1
jmp .endif_0
.else_0:
.endif_0:
ldw i0, (lb) -4
push i0
ldw i0, (lb) -4
mov i1, 1
sub i0, i1
push i0
call Faculty
pop i1
pop i0
mul i0, i1
push i0
ret (1) 1
; --- Procedure Definition "GCD" ---
GCD:
; If Statement
ldw i0, (lb) -8
xor i1, i1
push i1
push i0
call Intr.CmpE
pop i0
xor i1, i1
cmp i0, i1
je .else_1
ldw i0, (lb) -4
push i0
ret (1) 2
jmp .endif_1
.else_1:
.endif_1:
ldw i0, (lb) -4
push i0
ldw i1, (lb) -8
pop i0
mod i0, i1
push i0
ldw i0, (lb) -8
push i0
call GCD
ret (1) 2
; --- Procedure Definition "Fibonacci" ---
Fibonacci:
; If Statement
ldw i0, (lb) -4
xor i1, i1
push i1
push i0
call Intr.CmpLE
pop i0
xor i1, i1
cmp i0, i1
je .else_2
push 0
ret (1) 1
jmp .endif_2
.else_2:
; If Statement
ldw i0, (lb) -4
mov i1, 1
push i1
push i0
call Intr.CmpE
pop i0
xor i1, i1
cmp i0, i1
je .else_3
push 1
ret (1) 1
jmp .endif_2
.else_3:
.endif_2:
ldw i0, (lb) -4
mov i1, 1
sub i0, i1
push i0
call Fibonacci
ldw i0, (lb) -4
mov i1, 2
sub i0, i1
push i0
call Fibonacci
pop i1
pop i0
add i0, i1
push i0
ret (1) 1
; --- Procedure Definition "FibonacciIt" ---
FibonacciIt:
; If Statement
ldw i0, (lb) -4
xor i1, i1
push i1
push i0
call Intr.CmpLE
pop i0
xor i1, i1
cmp i0, i1
je .else_4
push 0
ret (1) 1
jmp .endif_3
.else_4:
; If Statement
ldw i0, (lb) -4
mov i1, 1
push i1
push i0
call Intr.CmpE
pop i0
xor i1, i1
cmp i0, i1
je .else_5
push 1
ret (1) 1
jmp .endif_3
.else_5:
.endif_3:
; Variable Initialization "a"
inc sp
xor i0, i0
stw i0, (lb) 8
; Variable Initialization "b"
inc sp
mov i0, 1
stw i0, (lb) 12
; Variable Initialization "i"
inc sp
mov i0, 2
stw i0, (lb) 16
; Variable Initialization "aa"
inc sp
xor i0, i0
stw i0, (lb) 20
; Variable Initialization "bb"
inc sp
xor i0, i0
stw i0, (lb) 24
; While Loop
.while_loop_0:
ldw i0, (lb) 16
push i0
ldw i1, (lb) -4
pop i0
push i1
push i0
call Intr.CmpLE
pop i0
xor i1, i1
cmp i0, i1
je .while_loop_0_end
; Variable Assignment "aa"
ldw i1, (lb) 12
ldw i0, (lb) 20
mov i0, i1
stw i0, (lb) 20
; Variable Assignment "bb"
ldw i0, (lb) 8
push i0
ldw i1, (lb) 12
pop i0
add i0, i1
mov i1, i0
ldw i0, (lb) 24
mov i0, i1
stw i0, (lb) 24
; Variable Assignment "a"
ldw i1, (lb) 20
ldw i0, (lb) 8
mov i0, i1
stw i0, (lb) 8
; Variable Assignment "b"
ldw i1, (lb) 24
ldw i0, (lb) 12
mov i0, i1
stw i0, (lb) 12
; Variable Assignment "i"
mov i1, 1
ldw i0, (lb) 16
add i0, i1
stw i0, (lb) 16
jmp .while_loop_0
.while_loop_0_end:
ldw i0, (lb) 12
push i0
ret (1) 1
sub sp, 5
; --- Procedure Definition "PrintFaculty" ---
PrintFaculty:
; Variable Initialization "result"
inc sp
ldw i0, (lb) -4
push i0
call Faculty
pop i0
stw i0, (lb) 8
ldw i0, (lb) -4
push i0
call Intr.PrintInt
push str_lit_0
call Intr.Print
ldw i0, (lb) 8
push i0
call Intr.PrintInt
push str_lit_1
call Intr.PrintLn
dec sp
ret (0) 1
; --- Procedure Definition "PrintGCD" ---
PrintGCD:
; Variable Initialization "result"
inc sp
ldw i0, (lb) -8
push i0
ldw i0, (lb) -4
push i0
call GCD
pop i0
stw i0, (lb) 8
push str_lit_2
call Intr.Print
ldw i0, (lb) -4
push i0
call Intr.PrintInt
push str_lit_3
call Intr.Print
ldw i0, (lb) -8
push i0
call Intr.PrintInt
push str_lit_4
call Intr.Print
ldw i0, (lb) 8
push i0
call Intr.PrintInt
push str_lit_1
call Intr.PrintLn
dec sp
ret (0) 2
; --- Procedure Definition "PrintFibonacci" ---
PrintFibonacci:
; Variable Initialization "result"
inc sp
ldw i0, (lb) -4
push i0
call FibonacciIt
pop i0
stw i0, (lb) 8
push str_lit_5
call Intr.Print
ldw i0, (lb) -4
push i0
call Intr.PrintInt
push str_lit_4
call Intr.Print
ldw i0, (lb) 8
push i0
call Intr.PrintInt
push str_lit_1
call Intr.PrintLn
dec sp
ret (0) 1
; --- Procedure Definition "Main" ---
Main:
push str_lit_1
call Intr.PrintLn
push str_lit_6
call Intr.PrintLn
; Range-Based For Loop
inc sp
mov i0, 1
.for_loop_0:
; Loop Condition
mov i1, 25
cmp i0, i1
jg .for_loop_0_end
stw i0, (lb) 8
ldw i0, (lb) 8
push i0
call PrintFibonacci
ldw i0, (lb) 8
inc i0
jmp .for_loop_0
.for_loop_0_end:
dec sp
push str_lit_7
call Intr.PrintLn
ret (0) 0
; --- Data Field Section ---
str_lit_1:
DATA.string ""
str_lit_0:
DATA.string "! = "
str_lit_4:
DATA.string ") = "
str_lit_3:
DATA.string ", "
str_lit_6:
DATA.string "Fibonacci Series:"
str_lit_7:
DATA.string "\n"
str_lit_5:
DATA.string "fib("
str_lit_2:
DATA.string "gcd("
; ================
|