-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.asm
403 lines (394 loc) · 4.62 KB
/
code.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
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
.MODEL SMALL
.STACK 100H
.DATA
V_x_0 DW ?
V_retsquare_1 DW ?
V_ret_2 DW ?
T__3 DW ?
V_a_4 DW ?
V_b_5 DW ?
V_retsum_6 DW ?
V_ret_7 DW ?
T__8 DW ?
V_n_9 DW ?
V_retfibo_10 DW ?
T__11 DW ?
T__12 DW ?
V_ret_13 DW ?
T__14 DW ?
T__15 DW ?
T__16 DW ?
T__17 DW ?
T__18 DW ?
V_n_19 DW ?
V_retfactorial_20 DW ?
T__21 DW ?
V_ret_22 DW ?
T__23 DW ?
T__24 DW ?
T__25 DW ?
V_retmain_26 DW ?
V_a_27 DW ?
V_b_28 DW ?
V_sumval_29 DW ?
V_sqval_30 DW ?
V_total_31 DW ?
V_n_32 DW ?
V_fn_33 DW ?
T__34 DW ?
T__35 DW ?
V_fact_36 DW ?
T__37 DW ?
T__38 DW ?
V_series_sum_39 DW ?
V_i_40 DW ?
T__41 DW ?
T__42 DW ?
T__43 DW ?
T__44 DW ?
V_p_45 DW ?
V_q_46 DW ?
V_r_47 DW ?
T__48 DW ?
T__49 DW ?
T__50 DW ?
T__51 DW ?
T__52 DW ?
T__53 DW ?
T__54 DW ?
.CODE
PRINTLN PROC
PUSH AX
PUSH BX
PUSH CX
PUSH DX
OR AX, AX
JGE ENDIF1
PUSH AX
MOV DL, '-'
MOV AH, 2
INT 21H
POP AX
NEG AX
ENDIF1:
XOR CX, CX
MOV BX, 10D
REPEAT1:
XOR DX, DX
DIV BX
PUSH DX
INC CX
OR AX, AX
JNE REPEAT1
MOV AH, 2
PRINTLOOP:
POP DX
OR DL, 30H
INT 21H
LOOP PRINTLOOP
MOV AH,2
MOV DX,0AH
INT 21H
MOV DX,0DH
INT 21H
POP DX
POP CX
POP BX
POP AX
RET
PRINTLN ENDP
square PROC
MOV AX, V_x_0
MOV BX, V_x_0
MUL BX
MOV T__3, AX
MOV V_ret_2, AX
MOV V_retsquare_1, AX
RET
square ENDP
sum PROC
MOV AX, V_a_4
ADD AX, V_b_5
MOV T__8, AX
MOV V_ret_7, AX
MOV V_retsum_6, AX
RET
sum ENDP
fibo PROC
MOV AX, V_n_9
CMP AX, 0
JE LABEL_0
MOV T__11, 0
JMP LABEL_2
LABEL_0:
MOV T__11, 1
LABEL_2:
MOV AX, T__11
CMP AX, 0
JE LABEL_3
MOV AX, 0
MOV V_retfibo_10, AX
RET
LABEL_3:
MOV AX, V_n_9
CMP AX, 1
JE LABEL_4
MOV T__12, 0
JMP LABEL_6
LABEL_4:
MOV T__12, 1
LABEL_6:
MOV AX, T__12
CMP AX, 0
JE LABEL_7
MOV AX, 1
MOV V_retfibo_10, AX
RET
LABEL_7:
MOV AX, V_n_9
SUB AX, 1
MOV T__14, AX
PUSHA
PUSH V_n_9
PUSH T__11
PUSH T__12
PUSH V_ret_13
PUSH T__14
PUSH T__15
MOV AX, T__14
MOV V_n_9, AX
CALL fibo
POP T__15
POP T__14
POP V_ret_13
POP T__12
POP T__11
POP V_n_9
POPA
MOV AX, V_retfibo_10
MOV T__15, AX
MOV AX, V_n_9
SUB AX, 2
MOV T__16, AX
PUSHA
PUSH V_n_9
PUSH T__11
PUSH T__12
PUSH V_ret_13
PUSH T__14
PUSH T__15
PUSH T__16
PUSH T__17
MOV AX, T__16
MOV V_n_9, AX
CALL fibo
POP T__17
POP T__16
POP T__15
POP T__14
POP V_ret_13
POP T__12
POP T__11
POP V_n_9
POPA
MOV AX, V_retfibo_10
MOV T__17, AX
MOV AX, T__15
ADD AX, T__17
MOV T__18, AX
MOV V_ret_13, AX
MOV V_retfibo_10, AX
RET
fibo ENDP
factorial PROC
MOV AX, V_n_19
CMP AX, 0
JE LABEL_8
MOV T__21, 0
JMP LABEL_10
LABEL_8:
MOV T__21, 1
LABEL_10:
MOV AX, T__21
CMP AX, 0
JE LABEL_11
MOV AX, 1
MOV V_retfactorial_20, AX
RET
LABEL_11:
MOV AX, V_n_19
SUB AX, 1
MOV T__23, AX
PUSHA
PUSH V_n_19
PUSH T__21
PUSH V_ret_22
PUSH T__23
PUSH T__24
MOV AX, T__23
MOV V_n_19, AX
CALL factorial
POP T__24
POP T__23
POP V_ret_22
POP T__21
POP V_n_19
POPA
MOV AX, V_retfactorial_20
MOV T__24, AX
MOV V_ret_22, AX
MOV BX, V_n_19
MUL BX
MOV T__25, AX
MOV V_ret_22, AX
MOV V_retfactorial_20, AX
RET
factorial ENDP
main PROC
MOV AX, @DATA
MOV DS, AX
MOV AX, 5
MOV V_n_32, AX
PUSHA
PUSH V_n_9
PUSH T__11
PUSH T__12
PUSH V_ret_13
PUSH T__14
PUSH T__15
PUSH T__16
PUSH T__17
PUSH T__18
MOV AX, V_n_32
MOV V_n_9, AX
CALL fibo
POP T__18
POP T__17
POP T__16
POP T__15
POP T__14
POP V_ret_13
POP T__12
POP T__11
POP V_n_9
POPA
MOV AX, V_retfibo_10
MOV T__34, AX
MOV V_fn_33, AX
CALL PRINTLN
PUSHA
PUSH V_n_19
PUSH T__21
PUSH V_ret_22
PUSH T__23
PUSH T__24
PUSH T__25
MOV AX, V_n_32
MOV V_n_19, AX
CALL factorial
POP T__25
POP T__24
POP T__23
POP V_ret_22
POP T__21
POP V_n_19
POPA
MOV AX, V_retfactorial_20
MOV T__37, AX
MOV V_fact_36, AX
CALL PRINTLN
MOV AX, 0
MOV V_series_sum_39, AX
MOV AX, 0
MOV V_i_40, AX
LABEL_15:
MOV AX, V_i_40
CMP AX, V_n_32
JL LABEL_12
MOV T__41, 0
JMP LABEL_14
LABEL_12:
MOV T__41, 1
LABEL_14:
MOV AX, T__41
CMP AX, 0
JE LABEL_16
MOV AX, V_series_sum_39
ADD AX, V_i_40
MOV T__43, AX
MOV V_series_sum_39, AX
MOV AX, V_i_40
INC AX
MOV V_i_40, AX
JMP LABEL_15
LABEL_16:
MOV AX, V_series_sum_39
CALL PRINTLN
MOV AX, 10
MOV V_p_45, AX
MOV AX, 5
MOV V_q_46, AX
MOV AX, 9
MOV V_r_47, AX
MOV AX, V_p_45
CMP AX, V_q_46
JG LABEL_17
MOV T__48, 0
JMP LABEL_19
LABEL_17:
MOV T__48, 1
LABEL_19:
MOV AX, T__48
CMP AX, 0
JE LABEL_31
MOV AX, V_p_45
CMP AX, V_r_47
JG LABEL_20
MOV T__49, 0
JMP LABEL_22
LABEL_20:
MOV T__49, 1
LABEL_22:
MOV AX, T__49
CMP AX, 0
JE LABEL_24
MOV AX, V_p_45
CALL PRINTLN
MOV AH, 4CH
INT 21H
JMP LABEL_23
LABEL_24:
MOV AX, V_r_47
CALL PRINTLN
MOV AH, 4CH
INT 21H
LABEL_23:
JMP LABEL_30
LABEL_31:
MOV AX, V_q_46
CMP AX, V_r_47
JG LABEL_25
MOV T__52, 0
JMP LABEL_27
LABEL_25:
MOV T__52, 1
LABEL_27:
MOV AX, T__52
CMP AX, 0
JE LABEL_29
MOV AX, V_q_46
CALL PRINTLN
MOV AH, 4CH
INT 21H
JMP LABEL_28
LABEL_29:
MOV AX, V_r_47
CALL PRINTLN
MOV AH, 4CH
INT 21H
LABEL_28:
LABEL_30:
MOV AH, 4CH
INT 21H
main ENDP
END MAIN