-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab3.asm
349 lines (259 loc) · 9.27 KB
/
lab3.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
.model small
.stack 100h
.data
MaxArrayLength equ 30
MaxNumber equ 7FFFh
MinNumber equ 8000h
ArrayLength db ?
ErrorCode db ?
Sign db ?
DirectionFlag db ?
EqualCounter db 0
Array dw MaxArrayLength dup (0)
Buffer dw ?
MaxNumLength db 7
RealLength db ?
buff db 7 dup (0)
InputArrayLengthMsg db 0Dh,'Input array length: $'
InputNumbers db 0Dh,'Input numbers:', '$'
InputError db 0Dh,'Incorrect value!', 0Ah, 0Dh, '$'
LengthError db 0Dh,'Array length should be geater than 0 and not grater than 30!', 0Ah, '$'
IncreasingSequence db 0Dh,'Increasing sequence', 0Ah, '$'
DecreasingSequence db 0Dh,'Decreasing sequence', 0Ah, '$'
RandomSequence db 0Dh,'Random sequence', 0Ah, '$'
EqualSequence db 0Dh,'All numbers are equal', 0Ah, '$'
newLineStr db 0Ah, 0Dh, '$'
.code
inputArrayLength proc
mov cx, 1
inputLoop:
printString InputArrayLengthMsg
call inputValue
cmp ErrorCode, 0
jnz inputLoop
cmp Buffer, MaxArrayLength
jg inputLoopError
cmp Buffer, 0
jg success
inputLoopError:
printString LengthError
jmp inputLoop
success:
mov bx, Buffer
mov ArrayLength, bl
printString InputNumbers
printString newLineStr
loop inputLoop
ret
endp
printString macro string
push ax
push dx
mov dx, offset string
mov ah, 9
int 21h
pop dx
pop ax
endm
inputArray proc
xor di,di
mov cl,ArrayLength
inputArrayLoop:
call inputValue
cmp ErrorCode, 0
jnz inputArrayLoop
push bx
xor bx, bx
mov bx, Buffer
jo inputArrayLoop
mov Array[di], bx
add di, 2
pop bx
loop inputArrayLoop
ret
endp
inputValue proc
push cx
inputElMain:
mov Buffer, 0
mov ah,0Ah
lea dx, MaxNumLength
int 21h
printString newLineStr
cmp RealLength,0
je inputValueError
mov Sign, 0
xor bx,bx
mov bl,RealLength
lea si,RealLength
add si,bx
mov bx,1
xor cx,cx
mov cl,RealLength
inputElLoop:
std
lodsb
call checkSymbol
mov ah, 0
cmp ErrorCode, 1
je inputValueError
cmp ErrorCode,2
je nextSymbol
sub al,'0'
mul bx
cmp ErrorCode, 0
jnz inputValueError
add Buffer,ax
jo checkIfMin
js checkIfMin
jmp checkScope
checkIfMin:
cmp Buffer, MinNumber
je checkNumLength
jne inputValueError
checkNumLength:
cmp RealLength, 6
je continue
jne inputValueError
checkScope:
push dx
mov dx, Buffer
cmp dx, MaxNumber
jg inputValueError
cmp dx, MinNumber
jl inputValueError
pop dx
continue:
mov ax,bx
mov bx,10
mul bx
cmp ErrorCode, 0
jz toNextSymbol
toNextSymbol:
mov bx,ax
jmp nextSymbol
inputValueError:
printString InputError
jmp inputArrayLoop
jmp exitInputEl
nextSymbol:
mov ErrorCode, 0
loop inputElLoop
cmp Sign, 0
je exitInputEl
neg Buffer
exitInputEl:
pop cx
ret
endp
checkSymbol proc
cmp al,'-'
je SignSymbol
cmp al,'9'
ja checkSymbolError
cmp al,'0'
jb checkSymbolError
jmp exitCheckGood
SignSymbol:
cmp si,offset RealLength
je exitWithMinus
checkSymbolError:
mov ErrorCode, 1
jmp checkSymbolExit
exitWithMinus:
mov ErrorCode, 2
mov Sign, 1
cmp RealLength, 1
je checkSymbolError
jmp checkSymbolExit
exitCheckGood:
mov ErrorCode, 0
checkSymbolExit:
ret
endp
CheckArray proc
push cx
push ax
xor cx, cx
xor di, di
mov cl, ArrayLength
sub cl, 2
mov ax, Array[di]
cmp ax, Array[di + 2]
jg set_decreasing
jl set_increasing
je set_equal
set_increasing:
mov DirectionFlag, 1
jmp checkAllArray:
set_decreasing:
mov DirectionFlag, 0
jmp checkAllArray
set_equal:
mov DirectionFlag, 2
mov EqualCounter, 1
checkAllArray:
add di, 2
mov ax, Array[di]
cmp ax, Array[di + 2]
jg checkIfDec
jl checkIfInc
je incrECntr
checkIfInc:
cmp DirectionFlag, 2
je prevEqInc
jne prevNotEqInc
prevEqInc:
mov DirectionFlag, 1
jmp toNext
prevNotEqInc:
cmp DirectionFlag, 1
jne randomSeq
jmp toNext
checkIfDec:
cmp DirectionFlag, 2
je prevEqDec
jne prevNotEqDec
prevEqDec:
mov DirectionFlag, 0
jmp toNext
prevNotEqDec:
cmp DirectionFlag, 0
jne randomSeq
jmp toNext
incrECntr:
inc EqualCounter
toNext:
loop checkAllArray
mov al, EqualCounter
inc al
cmp al, ArrayLength
je equalSeq
cmp DirectionFlag, 1
je increasingSeq
jne decreasingSeq
increasingSeq:
printString IncreasingSequence
jmp endProgram
decreasingSeq:
printString DecreasingSequence
jmp endProgram
randomSeq:
printString RandomSequence
jmp endProgram
equalSeq:
printString EqualSequence
endProgram:
xor ax, ax
mov ah,4ch
int 21h
ret
endp
start:
mov ax,@data
mov ds,ax
xor ax,ax
call inputArrayLength
call inputArray
call CheckArray
end start