-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab3.asm
More file actions
246 lines (229 loc) · 4.96 KB
/
lab3.asm
File metadata and controls
246 lines (229 loc) · 4.96 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
.MODEL small
.STACK 100h
.code
OutInt proc
test ax, ax
jns oi1
mov cx, ax
mov ah, 02h
mov dl, '-'
int 21h
mov ax, cx
neg ax
oi1:
xor cx, cx
mov bx, 10
oi2:
xor dx,dx
div bx
push dx
inc cx
test ax, ax
jnz oi2
mov ah, 02h
oi3:
pop dx
add dl, '0'
int 21h
loop oi3
ret
OutInt endp
ChToInt proc near
xor ax, ax
xor bx, bx
Bigne:
imul dexs
cmp dl, 0h
je OverFlow2:
mov ax, 0900h
mov dx, offset OverFlowed
int 21h
mov ax, 4C00h
int 21h
OverFlow2:
mov dl, bx+si+2
inc bx
cmp dl, 2Dh
je NotnowNeg:
sub dl, 48
add ax, dx
cmp ax, 7FFFh
jle OverFlow1:
mov ax, 0900h
mov dx, offset OverFlowed
int 21h
mov ax, 4C00h
int 21h
OverFlow1:
NotnowNeg:
mov dl, bx+si+2
cmp dl, 0Dh
jne Bigne:
cmp si+2, 2Dh
jne NegativeTr:
mov dx, 0FFFFh
sub dx, ax
inc dx
mov ax, dx
NegativeTr:
RET
ChToInt endp
start:
mov ax, @data
mov ds, ax
mov ax, 0900h
mov dx, offset CountMessage
int 21h
mov ax, 0A00h
mov dx, offset sizeCh
int 21h
mov si, dx
CALL ChToInt
mov sizeInt, al
cmp ax, 0001h
jg not1: ; Cheking for less then 2 elem
mov ax, 4C00h
int 21h
not1:
mov ch, 00h
mov cl, sizeInt
mov si, offset massInt+1 ;entering massInt size
mov [si], cx
mov ax, 0900h
mov dx, offset NumbersMessage
int 21h
xor bp, bp
EnterNumb: ;cycle of entering mass
mov ax, 0A00h
mov dx, offset NumberCh
int 21h
mov si, dx
CALL ChToInt
mov si, offset massInt+2
add si, bp
add bp, 2h
mov [si], ax
cmp ax, MinNumb
jg MinFinding: ;Finding Min
mov MinNumb, ax
MinFinding:
cmp ax, MaxNumb
jl MaxFinding: ;Finding Max
mov MaxNumb, ax
MaxFinding:
mov ax, 0900h
mov dx, offset NewString
int 21h
sub cx, 1h
cmp cx, 0h
jne EnterNumb:
mov [si]+2, '$'
mov ax, 0900h ;Set Min Border
mov dx, offset MinBorderMess
int 21h
mov ax, 0A00h
mov dx, offset NumberCh
int 21h
mov si, dx
CALL ChToInt
mov si, offset MinBorder
mov [si], ax
mov ax, 0900h ;Set Max Border
mov dx, offset MaxBorderMess
int 21h
mov ax, 0A00h
mov dx, offset NumberCh
int 21h
mov si, dx
CALL ChToInt
mov si, offset MaxBorder
mov [si], ax
cmp ax, MinBorder
jge MaxNotLess:
mov ax, 0900h ;Set Min Border
mov dx, offset MaxLessMin
int 21h
mov ax, 4C00h
int 21h
MaxNotLess:
mov ax, MaxBorder
sub ax, MinBorder
mov A, ax
mov ax, MaxNumb
sub ax, MinNumb
mov A+2, ax
mov B+2, ax
mov ax, MaxBorder
imul A+2
mov bx, ax
mov ax, MaxNumb
imul A
sub bx, ax
mov B, bx
xor bp, bp
mov ch, 00h
mov cl, sizeInt
NewNumbersInt:
mov si, offset massInt+2
add si, bp
add bp, 2h
mov ax, [si]
imul A
add ax, B
xor dx, dx
test ax, ax
jns Ifless1:
mov dx, 0FFFFh
Ifless1:
idiv A+2
mov [si], ax
mov bx, dx
mov ax, A+2
sub cx, 1h
cmp cx, 0h
jne NewNumbersInt:
mov ax, 0900h
mov dx, offset OutPuting
int 21h
mov double, 0h
output:
mov bx, offset massInt
mov ax, double
add ax, 2h
mov double, ax
add bx, double
mov ax, [bx]
CALL OutInt
mov cx, massInt+1h
mov ch, 0h
sub cx, 1h
mov massInt+1, cx
mov ax, 0900h
mov dx, offset NewString
int 21h
cmp cx, 0
jne output:
mov ax, 4C00h
int 21h
.data
sizeCh db 3, ?, 3 dup (?), '$'
sizeInt db ?
NumberCh db 7, ?, 7 dup (?), '$'
massInt dw 61, ?, 61 dup (?), '$'
MinNumb dw 7FFFh ;Maximum existed val
MaxNumb dw 8000h ;Minimum existed val
MinBorder dw ?
MaxBorder dw ?
A dw ?, ?
B dw ?, ?
dexs dw 10
double dw 2h
OverFlowed db 0Ah, 0Dh, "Register OverFlowed", '$'
CountMessage db "Enter Count of numbers", 0Ah, 0Dh, '$'
NumbersMessage db 0Ah, 0Dh, "Enter your numbers", 0Ah, 0Dh, '$'
MinBorderMess db 0Ah, 0Dh, "Enter your Minimal border", 0Ah, 0Dh, '$'
MaxBorderMess db 0Ah, 0Dh, "Enter your Maximal border", 0Ah, 0Dh, '$'
MaxLessMin db 0Ah, 0Dh, "Max Border Cannot be less then Min Border" , 0Ah, 0Dh, '$'
OutPuting db 0Ah, 0Dh, "That is a result" , 0Ah, 0Dh, '$'
NewString db 0Ah, 0Dh, '$'
end start