-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL5.asm
More file actions
344 lines (322 loc) · 6.08 KB
/
L5.asm
File metadata and controls
344 lines (322 loc) · 6.08 KB
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
.model small
.stack 100h
.386
.data
sumbl db 1 dup(0)
buffercur db ?
argc dw 0
maxcmdsize equ 125
cmd_length dw ?
cmd_line db maxcmdsize+2,?,maxcmdsize dup(?)
buf db maxcmdsize+2,?,maxcmdsize dup('$')
filename db 126 dup("$")
localsize dw 0 ;size of string that user entered
number dw 0
stringinfile dw 0
String13 db "karetka ", 13,10, "$"
String10 db "LF found", 13,10, "$"
StringFileOpenMsg db "File was opened ", 13,10, "$"
StringFileCloseMsg db "File was closed ", 13,10, "$"
StringErrorComandLineMsg db "Comand Line Error size",13,10,"$"
StringFileErrorOpenMsg db "File Error Open", 13,10, "$"
StringFileErrorCloseMsg db "File Error Close", 13,10, "$"
StringBeginMsg db "The program has begun ", 13,10, "$"
StringErrorParsMsg db "Error pars params in comand line",13,10,"$"
StringErrorOwerflowMsg db "Error Owerflow of size:",13,10,"$"
StringEndMsg db "The program has end ", 13,10, "$"
StringinFileMsg db "The number of the matching line in the file: $"
StringAmpleAmountMsg db "Satisfying number of lines: $"
StringNewStr db 13,10,"$"
StringScobka db ") $"
StringSizeMsg db ". size: $"
StringPlusMsg db " + $"
flag db 0
boolsh db 0
counter db 0
.code
Print_str macro msg
push ax
push dx
mov ah,9
mov dx,offset msg
int 21h
pop dx
pop ax
endm
Show_AX proc
push bx
push cx
push dx
push ax
mov bx, 10
xor cx,cx
Convert:
xor dx,dx
div bx
add dl, 30h
push dx
inc cx
or ax, ax
jnz Convert
Show1:
pop dx
mov ah,2
int 21h
dec cx
jnz Show1
pop ax
pop dx
pop cx
pop bx
ret
Show_AX endp
IsEnough proc
inc stringinfile
push bx
cmp counter,0
jg finaly
cmp si,localsize
jae EndIsEnough ;jle
finaly:
inc number
push ax
mov ax,number
call Show_AX
pop ax
Print_str StringScobka
Print_str StringinFileMsg
push ax
mov ax,stringinfile
call Show_AX
Print_str StringSizeMsg
cmp counter,0
je finaly2
push ax
push cx
xor cx,cx
mov cl,counter
mov ax,65535
IsEnoughCycle:
call Show_AX
Print_str StringPlusMsg
loop IsEnoughCycle
pop cx
pop ax
finaly2:
mov ax,si
call Show_AX
pop ax
Print_str StringNewStr
EndIsEnough:
pop bx
ret
IsEnough endp
Makeparams proc
push si
push di
push dx
push cx
xor si,si
xor di,di
sravn:
cmp cmd_line[si],' '
jne nextstep
call SkipSpaces
inc argc
cmp argc,2
je second
cmp argc,3
je third
nextstep:
mov dl,cmd_line[si]
mov buf[di],dl
inc di
inc si
xor dx,dx
mov dx,cmd_length
cmp si,dx
jne sravn
jmp third
second:
mov cx,di
xor di,di
secondcycle:
xor dx,dx
mov dl,buf[di]
mov filename[di],dl
mov buf[di],"$"
inc di
loop secondcycle
mov filename[di],0
xor di,di
jmp sravn
third:
mov cx,di
xor di,di
thirdcycle:
cmp buf[di],30h
jl ErrorEnded2
cmp buf[di],39h
jg ErrorEnded2
push ax
push bx
mov bx,10
mov ax,localsize
mul bx
mov localsize,ax
pop bx
pop ax
jc ErrorEnded1
push ax
xor ax,ax
mov al,buf[di]
sub al,30h
add localsize,ax
pop ax
jc ErrorEnded1
inc di
loop thirdcycle
jmp EndMakeparams
ErrorEnded1:
pop cx
Print_str StringErrorOwerflowMsg
jmp ErrorEnds
ErrorEnded2:
Print_str StringErrorParsMsg
ErrorEnds:
pop cx
pop dx
pop si
pop di
jmp Exit
EndMakeparams:
pop cx
pop dx
pop si
pop di
ret
Makeparams endp
SkipSpaces proc
SkipCycle:
cmp cmd_line[si],' '
je skip
jmp EndSkip
skip:
inc si
jmp SkipCycle
EndSkip:
ret
SkipSpaces endp
start:
cmp boolsh, 1
jne m
dec stringinfile
m:
mov ax, @data
mov es, ax
xor cx,cx
mov cl,ds:[80h]
mov bx,cx
mov si,81h
mov di,offset cmd_line
rep movsb
mov ds,ax
Print_str StringBeginMsg ;the program has begun
mov cmd_length,bx
call Makeparams
mov dx,offset filename
mov ah,3Dh
mov al,00h
int 21h
jc ErrorExit2
Print_str StringFileOpenMsg
mov bx,ax
mov di,01
push si
Cycle:
call Read
jmp Cycle
Close:
call Ended
jmp Exit
ErrorExit1:
Print_str StringErrorComandLineMsg
jmp Exit
ErrorExit2:
Print_str StringFileErrorOpenMsg
jmp Exit
ErrorExit3:
Print_str StringFileErrorCloseMsg
Exit:
Print_str StringEndMsg
mov ax, 4c00h
int 21h
Read proc
push cx
push si
xor si,si
mov cx,1
ReadCycle:
mov dx,offset sumbl
mov al, sumbl
mov buffercur,al
mov ah,3Fh ;read from file
int 21h
jc ErrorExit2
mov cx,ax
jcxz Close
inc si
cmp si,65535
je @count
lstep:
cmp sumbl,10
je EndRead13
cmp sumbl,10
je EndRead0
jmp ReadCycle
@count:
inc counter
jmp lstep
EndRead13:
mov flag, 1
jmp EndRead
EndRead0:
cmp flag,1
jne EndRead
mov flag,0
dec stringinfile
EndRead:
cmp buffercur, 13
jne r
mov boolsh, 1
r:
dec si
call IsEnough
pop si
pop cx
ret
Read endp
Ended proc
cmp buf,13
call IsEnough
mov ah,3Eh
int 21h
jc ErrorExit3
Print_str StringNewStr
Print_str StringAmpleAmountMsg
push ax
mov ax,number
call Show_AX
pop ax
Print_str StringNewStr
Print_str StringFileCloseMsg
jmp endEnded
ErrorExitl:
Print_str StringFileErrorCloseMsg
Print_str StringEndMsg
mov ax, 4c00h
int 21h
endEnded:
ret
Ended endp
end start