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
| org 100h
call kelet
call checkop
cmp op,'/'
jne tt
cmp num2,0
jne tt
ret
tt:
call sum
hlt
ret
st db 10,13,'error',10,13,'$'
oppp db '+-*/$'
a dw offset minus, offset digit, offset mix,offset mix,offset mix,offset opp1,offset minus, offset digit, offset mix2, offset mix2, offset mix2,offset opp2
ferror dw 0
sum dw 0
mflag dw 0
finish dw 0
num1 dw 0
num2 dw 0
op db 0
x dd 1000000000,100000000,10000000,1000000,100000,10000,1000,100,10,1
res db '0000000000$'
sherit dw 0
kelet: call hit
xx: call tav
call [di]
add di,2
cmp ferror,1
jne f1
call error
jmp kelet
f1: cmp finish,1
jne xx
call nog
ret
hit: mov sum,0
mov ferror,0
mov mflag,0
mov finish,0
lea di,a
ret
tav: mov ah,1
int 21h
ret
error: mov ah,9
lea dx,st
int 21h
ret
nog: mov ax,sum
cmp mflag,1
jne n1
neg ax
n1: mov num2,ax
ret
mix: call digit
cmp ferror,1
jne m1
call opp1
m1:ret
opp1: mov si,0
o3:cmp oppp[si],'$'
je o1
cmp al,oppp[si]
je o2
inc si
jmp o3
o1: mov ferror,1
ret
o2: mov op,al
call nog
mov num1,ax
call hit2
ret
minus: cmp al,'-'
jne x1
mov mflag,1
ret
x1: call digit
add di,2
ret
digit: cmp al,'0'
jb d1
cmp al,'9'
ja d1
call sumnumber
ret
d1: mov ferror,1
ret
sumnumber: mov ah,0
sub al,30h
xchg ax,sum
mov cx,10
mul cx
add sum,ax
ret
mix2: call digit
cmp ferror,1
jne h1
call opp2
h1:ret
opp2: cmp al,'='
je j2
mov ferror,1
ret
j2:mov finish,1
mov ferror,0
ret
hit2: call hit
add di,10
ret
checkop: cmp op,'+'
je t1
cmp op,'-'
je t2
cmp op,'*'
je t3
cmp op,'/'
je t4
t1: call addition
ret
t2: call soustraction
ret
t3: call multiplication
ret
t4: call division
ret
addition: mov ax,num1
add ax,num2
add ax,0
jns g
neg ax
mov cx,ax
mov dl,'-'
mov ah,2
int 21h
mov ax,cx
g: mov dx,0
ret
soustraction: mov ax,num1
sub ax,num2
add ax,0
mov dx,0
jns f
neg ax
mov cx,ax
mov dl,'-'
mov ah,2
int 21h
mov ax,cx
f: mov dx,0
ret
multiplication: mov ax,num1
mov bx,num2
imul bx
add dx,0
jns l
not dx
neg ax
mov cx,ax
mov bx,dx
mov dl,'-'
mov ah,2
int 21h
mov ax,cx
mov dx,bx
l: ret
division: mov ax,num1
mov bx,num2
cmp num2,0
jne uu
call error
ret
uu: mov dx,0
idiv bx
mov sherit,dx
mov dx,0
add ax,0
jns ly
not dx
neg ax
mov cx,ax
mov bx,dx
mov dl,'-'
mov ah,2
int 21h
mov ax,cx
mov dx,bx
ly: ret
res: lea si,x
lea di,res
xo: cmp ax,0
jne d
cmp dx,0
je sof1
d: mov bx,[si]
add si,2
mov cx,[si]
ff: sub ax,bx
sbb dx,cx
jc tikoon
inc byte PTR[di]
jmp ff
tikoon: add ax,bx
adc dx,cx
add si,2
inc di
jmp xo
sof1: lea si,res
yo: cmp [si+1],'$'
je zo
cmp [si],'0'
jne zo
inc si
jmp yo
zo: lea dx,si
mov ah,9
int 21h
cmp sherit,0
je yyy
call yeter
yyy: ret
yeter: mov dl,'.'
mov ah,2
int 21h
mov cx,5
yy: call kefelsherit
call divv
loop yy
ret
kefelsherit: mov ax, sherit
mov bx,10
mul bx
ret
print: mov dl,al
add dl,30h
mov ah,2
int 21h
ret
divv: mov dx,0
mov bx,num2
div bx
mov sherit,dx
call print
ret |
Partager