-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5.exe.~asm
509 lines (378 loc) · 5.4 KB
/
5.exe.~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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
.model small
.stack 100h
.data
file db 200 dup (?)
file2 db 200 dup (?)
file1 db 200 dup (?)
size db ?
flagBeginFile db 0
buf db 50 dup (?)
handler1 dw 0
handler2 dw 0
wordForFind 50,?,50 dup (?)
errorMessage db "error$",0Dh,0Ah
.code
start:
mov ax, @data
mov es, ax
mov cl, ds:[80h]
mov si, 81h
lea di,file
rep movsb
mov ds,ax
lea si,file
checkSpace1:
cmp [si],0
je errorCommandLine
cmp [si],' '
jne readFile1
inc si
jmp checkSpace1
readFile1:
lea di,file1
cycleReadNameFile1:
mov al,[si]
mov [di],al
inc di
inc si
cmp [si],0
je errorCommandLine
cmp [si], '.'
je readTxt
cmp [si], ' '
jne cycleReadNameFile1
setTXT:
cmp [si], ' '
jne errorCommandLine
mov [di],'.'
inc di
mov [di],'t'
inc di
mov [di],'x'
inc di
mov [di],'t'
inc di
jmp endReadNameFile1
readTXT:
cmp [si],'.'
jne errorCommandLine
mov [di],'.'
inc di
inc si
cmp [si],'t'
jne errorCommandLine
mov [di],'t'
inc di
inc si
cmp [si],'x'
jne errorCommandLine
mov [di],'x'
inc di
inc si
cmp [si],'t'
jne errorCommandLine
mov [di],'t'
inc di
inc si
endReadNameFile1:
mov byte ptr [di],0
checkSpace2:
cmp [si],0
je errorCommandLine
cmp [si],' '
jne readNameFile2
inc si
jmp checkSpace2
readNameFile2:
lea di,file2
cycleReadNameFile2:
mov al,[si]
mov [di],al
inc di
inc si
cmp [si],0
je errorCommandLine
cmp [si], '.'
je readTxt2
cmp [si], ' '
jne cycleReadNameFile2
setTXT2:
cmp [si], ' '
jne errorCommandLine
mov [di],'.'
inc di
mov [di],'t'
inc di
mov [di],'x'
inc di
mov [di],'t'
inc di
jmp endReadNameFile2
readTXT2:
cmp [si],'.'
jne errorCommandLine
mov [di],'.'
inc di
inc si
dec size
cmp [si],'t'
jne errorCommandLine
mov [di],'t'
inc di
inc si
dec size
cmp [si],'x'
jne errorCommandLine
mov [di],'x'
inc di
inc si
dec size
cmp [si],'t'
jne errorCommandLine
mov [di],'t'
inc di
inc si
endReadNameFile2:
mov byte ptr [di],0
checkSpace3:
cmp [si],0
je errorCommandLine
cmp [si],' '
jne readWord
inc si
jmp checkSpace3
readWord:
lea di,wordForFind
add di,2
mov al,[si]
mov [di],al
inc si
inc di
add wordForFind[1],1
cycleReadWord:
mov al,[si]
cmp [si],' '
je nextCheckCommandLine
cmp [si],0
je nextCheckCommandLine
mov [di],al
add wordForFind[1],1
inc si
inc di
jmp cycleReadWord
nextCheckCommandLine:
cmp [si],' '
je nextSymbolCheckCommandLine
cmp [si],0
je openFiles
jmp errorCommandLine
nextSymbolCheckCommandLine:
inc si
jmp nextCheckCommandLine
errorCommandLine:
lea dx,errorMessage
mov ah,9
int 21h
jmp exitFromProgramm
openFiles:
mov ah, 3Dh
mov al, 00
mov cl,01h
mov dx, offset file1
int 21h
jc errorCommandLine
mov handler1,ax
mov ah, 3Dh
mov al, 02h
mov cl,0h
mov dx, offset file2
int 21h
jc errorCommandLine
mov handler2,ax
xor di,di
lea dx,buf
mov ah,3Fh
mov bx,handler1
mov cx,1
int 21h
mov al,buf[di]
cmp al,0Dh
je setBeginFlag
mov ah,42h
mov bx,handler1
mov al,0
mov cx,0
mov dx,0
int 21h
jmp find
setBeginFlag:
mov flagBeginFile,1
jmp exitFromOutputInFile2
find:
lea dx,buf
lea si,wordForFind
add si,2
mov ah,3Fh
mov bx,handler1
mov cx,1
int 21h
cmp al,0
je output
cmp buf[di],0Ah
je find
cmp buf[di],0Dh
je output
cmp buf[di],' '
je find
mov al,buf[di]
cmp al,[si]
jne missWord
je findWord
jmp find
findWord:
inc si
mov cl,wordForFind[1]
dec cl
cycleFindWord:
push cx
lea dx,buf
mov ah,3Fh
mov bx,handler1
mov cx,1
int 21h
pop cx
cmp cl,0
jg ifSizeNo0
cmp al,0
je exit
cmp buf[di],' '
je moveNewLine
cmp buf[di],0Dh
je find
jmp missWord
ifSizeNo0:
cmp al,0
je output
mov al,buf[di]
cmp al,0Dh
je output
cmp al,' '
je find
cmp al,[si]
jne missWord
inc si
loop cycleFindWord
mov ah,3Fh
mov bx,handler1
mov cx,1
int 21h
cmp al,0
je exit
mov al,buf[di]
cmp al,0Dh
je find
cmp al,' '
jne find
je moveNewLine
missWord:
mov ah,3Fh
mov bx,handler1
mov cx,1
int 21h
cmp buf[di],' '
je find
cmp buf[di],0Dh
je output
cmp al,0
je output
jmp missWord
moveNewLine:
mov ah,3Fh
mov bx,handler1
mov cx,1
int 21h
cmp al,0
je exit
cmp buf[di],0Dh
jne moveNewLine
mov flagBeginFile,1
jmp find
output:
cmp flagBeginFile,1
je outputNoFirstStrings
mov ah,42h
mov al,0
mov bx,handler1
mov cx,0
mov dx,0
int 21h
mov flagBeginFile,1
jmp outInFile2
outputNoFirstStrings:
xor di,di
xor cx,cx
mov ah,42h
mov al,1
mov bx,handler1
mov cx,-1
mov dx,-2
int 21h
lea dx,buf
mov ah,3Fh
mov cx,1
mov bx,handler1
int 21h
mov al,buf[di]
cmp buf[di],0Ah
je outInFile2
jmp outputNoFirstStrings
outInFile2:
mov flagBeginFile,1
mov ah,3Fh
mov cx,1
mov bx,handler1
lea dx,buf
int 21h
cmp al,0
je exit
cmp buf[di],0Dh
je exitFromOutputInFile2
lea dx,buf
xor al,al
mov ah,40h
mov cx,1
mov bx,handler2
int 21h
jmp outInFile2
exitFromOutputInFile2:
lea dx,buf
mov buf[di],0Dh
mov ah,40h
mov cx,1
mov bx,handler2
int 21h
lea dx,buf
mov buf[di],0Ah
mov ah,40h
mov cx,1
mov bx,handler2
int 21h
mov flagBeginFile,1
jmp find
exit:
cmp handler1,0
je closeFile2
mov ah,3Eh
mov bx,handler1
int 21h
closeFile2:
cmp handler2,0
je exitFromProgramm
mov ah,3Eh
mov bx,handler2
int 21h
exitFromProgramm:
mov ax,4C00h
int 21h
end start
; [SOURCE]: D:\emu8086\MyBuild\5.asm