forked from unknowxui/fasm-emu-user-interrupt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user-interrupt.asm
300 lines (231 loc) · 3.63 KB
/
user-interrupt.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
#fasm#
cli ;Clear Interrupt flag flag if = 0 block int
xor ax,ax
mov es,ax
mov bx,cs
mov ax,intProc
mov word[es:180h],ax
mov word[es:182h],bx
sti ; Set flag if - 1 UnBlock int
mov ax,cs
mov es,ax
mov bx,strSubA ;Sub
mov di,strSubALen
mov dx,strSubD
mov si,strSubDLen
mov al,6
int 60h
cmp ah,12
je errorFuncNotFound
mov bx,strSubA ;Sub
mov di,strSubALen
mov dx,strSubD
mov si,strSubDLen
mov al,2
int 60h
cmp ah,12
je errorFuncNotFound
mov dx,msgOutSub
xor ax,ax
mov ah,09h
int 21h
mov bx,msgSub
lea ax,[msgSubEnd- 1]
call to_str
mov dx,msgSub
xor ax,ax
mov ah,09h
int 21h
mov dx,msgOutAdd
xor ax,ax
mov ah,09h
int 21h
mov bx,strA ; add
mov di,strALen
mov dx,strD
mov si,strDLen
mov al,1
int 60h
cmp ah,12
je errorFuncNotFound
mov bx,msgAdd
lea ax,[msgAddEnd - 1]
call to_str
mov dx,msgAdd
xor ax,ax
mov ah,09h
int 21h
mov dx,msgOutMul
xor ax,ax
mov ah,09h
int 21h
mov bx,strMulA ; mul
mov di,strMulALen
mov dx,strMulD
mov si,strMulDLen
mov al,4
int 60h
cmp ah,12
je errorFuncNotFound
mov bx,msgMul
lea ax,[msgMulEnd- 1]
call to_str
mov dx,msgMul
xor ax,ax
mov ah,09h
int 21h
mov dx,msgOutDiv
xor ax,ax
mov ah,09h
int 21h
mov bx,strDivA ;Div
mov di,strDivALen
mov dx,strDivB
mov si,strDivBLen
mov al,3
int 60h
cmp ah,1
je errorFuncNotFound
mov bx,msgDiv
lea ax,[msgDivEnd- 1]
call to_str
mov dx,msgDiv
xor ax,ax
mov ah,09h
int 21h
xor ax,ax
mov al,0
int 21h
errorFuncNotFound:
xor ax,ax
mov dx,errorMsgA
mov ah,09h
int 21h
xor ax,ax
mov al,0
int 21h
intProc:
cmp al,1
je addStr
cmp al,2
je subStr
cmp al,3
je divStr
cmp al,4
je mulStr
mov ah,12 ; Function not found
stc
ret
addStr:
mov bp,di
call str_to_num
mov cx,ax
mov bx,dx
mov bp,si
call str_to_num
add cx,ax
ret
subStr:
mov bp,di
call str_to_num
mov cx,ax
mov bx,dx
mov bp,si
call str_to_num
sub cx,ax
ret
divStr:
mov bp,di
call str_to_num
mov cx,ax
mov bx,dx
mov bp,si
call str_to_num
div cl
mov cx,ax
ret
mulStr:
mov bp,di
call str_to_num
mov cx,ax
mov bx,dx
mov bp,si
call str_to_num
mul cx
mov cx,ax
ret
str_to_num:
push dx ; param: bx - array offset bp - array len
push cx
push si
push sp
mov dx,bp
mov bp,sp
sub sp,4
xor si,si
mov WORD[bp - 2],0
Loops:
mov cx,WORD[bx + si]
sub cx,30h
mov ax,WORD[bp - 2]
mov ah,al
mov al,cl
aad
mov [bp-2],ax
inc si
cmp si,dx
jne Loops
mov ax,[bp-2]
add sp,4
pop sp
pop si
pop cx
pop dx
ret
to_str:
push di
std
mov di,ax
mov ax,cx
mov cx,10
Repeata:
xor dx,dx
div cx
xchg ax,dx
add al,'0'
stosb
xchg ax,dx
or ax,ax
jne Repeata
mov ax,bx
pop di
ret
msgOutMul db " Mul str: ",'$'
msgMul db 5 dup(?), '$'
msgMulEnd = $-1
msgOutAdd db " Add str: ",'$'
msgAdd db 5 dup(?), '$'
msgAddEnd = $-1
msgOutDiv db " Div str: ",'$'
msgDiv db 5 dup(?) , '$'
msgDivEnd = $-1
msgOutSub db " Sub str: ",'$'
msgSub db 5 dup(?) , '$'
msgSubEnd = $-1
errorMsgA db "Error function not found ",'$'
strA db "2"
strALen = $ - strA
strD db "144"
strDLen = $ - strD
strMulA db "144"
strMulALen = $ - strMulA
strMulD db "2"
strMulDLen = $ - strMulD
strDivA db "2"
strDivALen = $ - strDivA
strDivB db "4"
strDivBLen = $ - strDivB
strSubA db "254"
strSubALen = $ - strSubA
strSubD db "127"
strSubDLen = $ - strSubD