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
| MODEL SMALL
.8086
DATASEG
vv db 13,10,'Enter number $'
vvv db 13,10,'Faktorial=$'
aa db 13,10,' || || |||||| || ||||| ||||| || || ||||||$'
br db 13,10,' || || || || || || || || || |||| |||| ||$'
cc db 13,10,' || |||| || |||||| || || || || || |||| || ||||||$'
da db 13,10,' $'
ee db 13,10,' || || |||||| |||||| ||||| ||||| || || ||||||$'
oo db 13,10,' |||| |||| || || || || || || || || || ||$'
ba db 13,10,' Kursova robota$'
dm db 13,10,' Studenta grupy CI-32$'
ca db 13,10,' Oleksandr$'
ea db 13,10,' Rozrakhunok faktorialu (1-9)$'
Question DB 13,10,'Continue? - [Y/N] $'
Errorr DB 13,10,' ERROR: Enter symbol again: $'
code SEGMENT
assume cs:code, ds:code
org 100h
entry_point:
jmp start
high_word_0 DW 0
high_word_1 DW 0
low_word_1 DW 0
result_string DB ' $'
start:
call welcome
a:
mov ax,@Data
mov ds,ax
mov dx,OFFSET vv
mov ah,09h
int 21h
;зчитати символ числа N
mov ah,1
INT 21h
;перевірка приналежності до діапазону '0'-'9'
cmp al,'0'
jl exit_error_input
cmp al,'9'
jg exit_error_input
;получити двійкове значення символу числа N
sub al,30h
call fakt
;обчислення факторіалу
mov ch,0
mov cl,al
mov ax,1
mov dx,0
;будем вважати що 0!=1
mul_loop:
cmp cx,0
je make_result_string
mov high_word_0,dx
mul cx
mov high_word_1,dx
mov low_word_1,ax
mov ax,high_word_0
mul cx
mov dx,ax
add dx,high_word_1
mov ax,low_word_1
dec cx
jmp mul_loop
make_result_string:
lea di,result_string+3 ;di -> '0'
add di,3
mov cx,10
div_loop:
div cx
add dl,30h
mov [di],dl
mov dx,0
cmp ax,0
je show_result_string
dec di
jmp div_loop
show_result_string:
mov ah,09h
lea dx,result_string
int 21h
jmp ansver
mov ah,01h
INT 21h
mov ax,4C00h
INT 21h
exit_error_input:
mov ax,4C01h
INT 21h
fakt:
push ax
mov ax,@Data
mov ds,ax
mov dx,OFFSET vvv
mov ah,09h
int 21h
pop ax
ret
ansver:
mov ax,@Data
mov ds,ax
mov dx,OFFSET Question
mov ah,09h
int 21h
EnterSymbol:
mov ah,01h
int 21h
cmp al,'Y'
jz IsYes
cmp al,'y'
jz IsYes
cmp al,'N'
jz IsNo
cmp al,'n'
jz IsNo
Error1:
mov dx, OFFSET Errorr
mov ah,09h
int 21h
jmp EnterSymbol
IsYes:
jmp a
IsNo:
mov ah,04ch
int 21h
pause:
xor cx,cx
mov dx,65535
mov ah,86h
int 15h
ret
welcome:
push ax
mov dx,OFFSET aa
mov ah,09h
int 21h
call Pause_50ms
mov dx,OFFSET br
call Write
call Pause_50ms
mov dx,OFFSET cc
call Write
call Pause_50ms
mov dx,OFFSET oo
call Write
call Pause_50ms
mov dx,OFFSET ee
call Write
call Pause_100ms
mov ax, 03
int 10h
mov dx,OFFSET da
mov ah,09h
int 21h
mov dx,OFFSET br
mov ah,09h
int 21h
mov dx,OFFSET cc
mov ah,09h
int 21h
mov dx,OFFSET oo
mov ah,09h
int 21h
mov dx,OFFSET ee
mov ah,09h
int 21h
call Write
call Pause_1ms
mov ax, 03
int 10h
mov dx,OFFSET da
mov ah,09h
int 21h
mov dx,OFFSET da
mov ah,09h
int 21h
mov dx,OFFSET cc
mov ah,09h
int 21h
mov dx,OFFSET oo
mov ah,09h
int 21h
mov dx,OFFSET ee
mov ah,09h
int 21h
call Write
call Pause_1ms
mov ax, 03
int 10h
mov dx,OFFSET da
mov ah,09h
int 21h
mov dx,OFFSET da
mov ah,09h
int 21h
mov dx,OFFSET da
mov ah,09h
int 21h
mov dx,OFFSET oo
mov ah,09h
int 21h
mov dx,OFFSET ee
mov ah,09h
int 21h
call Write
call Pause_1ms
mov ax, 03
int 10h
mov dx,OFFSET da
mov ah,09h
int 21h
mov dx,OFFSET da
mov ah,09h
int 21h
mov dx,OFFSET da
mov ah,09h
int 21h
mov dx,OFFSET da
mov ah,09h
int 21h
mov dx,OFFSET ee
mov ah,09h
int 21h
call Write
call Pause_1ms
mov ax, 03
int 10h
mov dx,OFFSET ba
mov ah,09h
int 21h
mov dx,OFFSET dm
mov ah,09h
int 21h
mov dx,OFFSET ca
mov ah,09h
int 21h
mov dx,OFFSET ea
mov ah,09h
int 21h
call Pause_100ms
mov ax, 03
int 10h
pop ax
ret
Pause_50ms PROC
mov cx, delay
Pause_1:
push cx
call pause
pop cx
loop Pause_1
ret
Pause_50ms ENDP
Pause_100ms PROC
mov cx, delay_100ms
Pause_2:
push cx
call pause
pop cx
loop Pause_2
ret
Pause_100ms ENDP
Pause_1ms PROC
mov cx, delay1
Pause_3:
push cx
call pause
pop cx
loop Pause_3
ret
Pause_1ms ENDP
Write Proc
push ax
mov ah,09h
int 21h
pop ax
ret
Write ENDP
code ENDS
END entry_point |