-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCALC.LST
3942 lines (3740 loc) · 145 KB
/
CALC.LST
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Turbo Assembler Version 4.1 04/04/16 21:24:55 Page 1
calc.asm
1 ; Calculator asemanator cu cel din Windows
2
3 .286
4 .287
5 include io.h
1 6 .xlist
1 7 ;
1 8 ; Declaratii de proceduri externe (implementate in IO.ASM)
1 9 ;
1 10 extrn itoa_proc:far, atoi_proc:far,puts_proc:far
1 11 extrn gets_proc:far, getc_proc:far,putc_proc:far
1 12 extrn puti_proc:far, putu_proc:far
1 13 extrn ftoa_proc:far, atof_proc:far, ftoa_sc_proc:far
1 14 extrn ltoa_proc:far
1 15
1 16 =000D cr equ 0dh ; Constante
1 17 =000A lf equ 0ah ; simbolice
1 18 =0009 tab equ 09h ; uzuale
1 19 ;
1 20 ; init_ds_es: Initializarea registrelor DS si ES
1 21 ;
1 22 init_ds_es macro
1 23 push ax
1 24 mov ax,dgroup
1 25 mov ds,ax
1 26 mov es,ax
1 27 pop ax
1 28 endm
1 29 ;
1 30 ; exit_dos: Iesire in DOS
1 31 ;
1 32 exit_dos macro
1 33 mov ax,4c00h
1 34 int 21h
1 35 endm
1 36 ;
1 37 ; itoa: Conversia Intreg-ASCII
1 38 ;
1 39 itoa macro dest,source
1 40 push ax
1 41 push di
1 42 mov ax,source ; Numar intreg
1 43 lea di,dest ; Adresa sir generat
1 44 call itoa_proc
1 45 pop di
1 46 pop ax
1 47 endm
1 48
1 49 ;
1 50 ; atoi: Conversie ASCII-Intreg
1 51 ;
1 52 atoi macro source
1 53 push si
1 54 lea si,source ; Adresa sir
1 55 call atoi_proc ; Rezultat in AX
1 56 pop si
1 57 endm
Turbo Assembler Version 4.1 04/04/16 21:24:55 Page 2
calc.asm
1 58 ;
1 59 ; inputs: Citire sir cu numar maxim admis de caractere
1 60 ;
1 61 inputs macro dest,length
1 62 push di
1 63 push cx
1 64 lea di,dest ; Adresa sir
1 65 mov cx,length ; Lungime maxima
1 66 call gets_proc
1 67 pop cx
1 68 pop di
1 69 endm
1 70 ;
1 71 ; getc: Citire caracter
1 72 ;
1 73 getc macro
1 74 call getc_proc ; Caracter in AL
1 75 endm
1 76 ;
1 77 ; puti: Afisare intreg cu semn
1 78 ;
1 79 puti macro n
1 80 push n ; Intreg
1 81 call far ptr puti_proc
1 82 add sp,2
1 83 endm
1 84 ;
1 85 ; putu: Afisare intreg fara semn
1 86 ;
1 87 putu macro n
1 88 push n ; Intreg
1 89 call far ptr putu_proc
1 90 add sp,2
1 91 endm
1 92 ;
1 93 ; geti: Citire intreg
1 94 ;
1 95 geti macro
1 96 local buff
1 97 .data
1 98 buff db 8 dup(0)
1 99 .code
1 100 inputs buff,7 ; Cel mult sapte cifre si semn
1 101 atoi buff ; ASCII-Intreg in AX
1 102 endm
1 103 ;
1 104 ; getu: Citire intreg fara semn
1 105 ;
1 106 getu macro
1 107 geti ; Este acelasi lucru cu geti
1 108 endm
1 109 ;
1 110 ; puts: Afisare sir
1 111 ;
1 112 puts macro x
1 113 push si
1 114 lea si,x ; Adresa sir
Turbo Assembler Version 4.1 04/04/16 21:24:55 Page 3
calc.asm
1 115 call puts_proc
1 116 pop si
1 117 endm
1 118 ;
1 119 ; putsi: Afisare sir imediat (din aceeasi linia)
1 120 ;
1 121 putsi macro x
1 122 local string
1 123 .data
1 124 string db x,0 ; Sir definit local
1 125 .code
1 126 puts string
1 127 endm
1 128 ;
1 129 ; gets: Citeste sir de la consola
1 130 ;
1 131 gets macro x
1 132 inputs x,80 ; Cel mult 80 de caractere
1 133 endm
1 134 ;
1 135 ; putc: Afisare un caracter
1 136 ;
1 137 putc macro x
1 138 push ax
1 139 mov al,x
1 140 call far ptr putc_proc
1 141 pop ax
1 142 endm
1 143 ;
1 144 ; getvec: Citeste vector de intrerupere
1 145 ;
1 146 getvec macro oldint,n
1 147 push bx
1 148 push ax
1 149 push es
1 150 mov al,n ; Nivel
1 151 mov ah,35h ; Apel
1 152 int 21h ; functie DOS
1 153 mov word ptr oldint,bx ; Adresa depunere
1 154 mov word ptr oldint+2,es ; vector citit
1 155 pop es
1 156 pop ax
1 157 pop bx
1 158 endm
1 159 ;
1 160 ; setvec: Modifica vector de intrerupere
1 161 ;
1 162 setvec macro newint,n
1 163 push ax
1 164 push ds
1 165 push dx
1 166 mov al,n ; Nivel
1 167 lds dx,newint ; Adresa vector nou
1 168 mov ah,25h ; Apel
1 169 int 21h ; functie DOS
1 170 pop dx
1 171 pop ds
Turbo Assembler Version 4.1 04/04/16 21:24:55 Page 4
calc.asm
1 172 pop ax
1 173 endm
1 174 ;
1 175 ; o_read: Deschide fisier pentru citire
1 176 ;
1 177 o_read macro fname,hand
1 178 mov ah,3dh
1 179 mov al,0c0h ; Mod acces
1 180 lea dx,fname ; Nume fisier
1 181 int 21h
1 182 mov hand,ax ; Depune handler
1 183 endm
1 184 ;
1 185 ; o_write: Deschide fisier pentru scriere
1 186 ;
1 187 o_write macro fname,hand
1 188 mov ah,3dh
1 189 mov al,0c1h ; Mod acces
1 190 lea dx,fname ; Nume fisier
1 191 int 21h
1 192 mov hand,ax ; Depune handler
1 193 endm
1 194 ;
1 195 ; o_creat: Creeaza fisier
1 196 ;
1 197 o_creat macro fname,hand
1 198 mov ah,3ch
1 199 mov cx,0 ; Atribute normale
1 200 lea dx,fname ; Nume fisier
1 201 int 21h
1 202 mov hand,ax ; Depune handler
1 203 endm
1 204 ;
1 205 ; f_read: Citeste date din fisier
1 206 ;
1 207 f_read macro hand,buf,nr
1 208 mov bx,hand ; Handler
1 209 mov cx,nr ; Numar de octeti
1 210 lea dx,buf ; Buffer (destinatie)
1 211 mov ah,3fh
1 212 int 21h
1 213 endm
1 214 ;
1 215 ; f_write: Scrie date in fisier
1 216 ;
1 217 f_write macro hand,buf,nr
1 218 mov bx,hand ; Handler
1 219 mov cx,nr ; Numar octeti
1 220 lea dx,buf ; Buffer (sursa)
1 221 mov ah,40h
1 222 int 21h ; AX = numar octeti
1 223 ; cititi efectiv
1 224 endm
1 225 ;
1 226 ; f_close: Inchidere fisier
1 227 ;
1 228 f_close macro hand
Turbo Assembler Version 4.1 04/04/16 21:24:55 Page 5
calc.asm
1 229 mov ah,3eh
1 230 mov bx,hand ; Handler
1 231 int 21h
1 232 endm
1 233 ;
1 234 ; set_dta: Fixeaza adresa zonei DTA
1 235 ;
1 236 set_dta macro dta
1 237 mov ah,1ah
1 238 lea dx,dta ; Adresa zonei DTA
1 239 ; (41 de octeti)
1 240 int 21h
1 241 endm
1 242 ;
1 243 ; find_first: Determina primul fisier dintr-un nume generic
1 244 ;
1 245 find_first macro name
1 246 mov ah,4eh
1 247 lea dx,name ; Nume generic
1 248 mov cx,0 ; Atribute normale
1 249 int 21h
1 250 endm
1 251 ;
1 252 ; find_next: Determina urmatorul fisier dintr-un nume generic
1 253 ;
1 254 find_next macro dta_area
1 255 mov ah,4fh
1 256 lea dx,dta_area ; Adresa zonei DTA
1 257 int 21h
1 258 endm
1 259
1 260 ; Operatii de conversie
1 261 _atof macro a_sir, a_num
1 262 push si
1 263 lea si, a_sir
1 264 push si
1 265 lea si, a_num
1 266 push si
1 267
1 268 call far ptr atof_proc
1 269 add sp, 4
1 270 pop si
1 271 endm
1 272
1 273 _ftoa macro val, sir
1 274 local x, maxim, minim, status, @@end, @@ftoa1, @@ftoa2
1 275
1 276 .data
1 277 maxim dd 2.147e09
1 278 minim dd 0.000001
1 279 status dw 0
1 280 x dd ?
1 281 .code
1 282 ; incarcam parametrii in stiva
1 283 push ax
1 284 lea ax, sir
1 285 push ax
Turbo Assembler Version 4.1 04/04/16 21:24:55 Page 6
calc.asm
1 286 mov ax, word ptr val + 2
1 287 push ax
1 288 mov ax, word ptr val
1 289 push ax
1 290
1 291 fld dword ptr [val]
1 292 fabs
1 293
1 294 ; comparam nr nostru in valoare absoluta cu maximul reprezentabil
1 295 fcom maxim
1 296
1 297 fstsw status
1 298 fwait
1 299 mov ax, status
1 300 sahf
1 301 ja @@ftoa2
1 302
1 303 ; comparam nr nostru in valoare absoluta cu minimul reprezentabil
1 304 fcomp minim
1 305
1 306 fstsw status
1 307 fwait
1 308 mov ax, status
1 309 sahf
1 310 jb @@ftoa2
1 311
1 312 @@ftoa1:
1 313 ; desc
1 314 fstp x
1 315 ; afisam nr in format normal
1 316 call far ptr ftoa_proc
1 317 jmp @@end
1 318 @@ftoa2:
1 319 fstp x
1 320 ; afisam nr in format stiintific
1 321 call far ptr ftoa_sc_proc
1 322 @@end:
1 323 add sp, 6
1 324 pop ax
1 325 endm
1 326 .sall
1 327 .list
328 include bios.asm
1 329 ; Fisier pentru lucrul cu BIOS
1 330
1 331 ; Constante pt culori
1 332 =0000 black equ 00h
1 333 =0001 blue equ 01h
1 334 =0002 green equ 02h
1 335 =0003 cyan equ 03h
1 336 =0004 red equ 04h
1 337 =0005 magenta equ 05h
1 338 =0006 brown equ 06h
1 339 =0007 white equ 07h
1 340 =0008 gray equ 08h
1 341 =0009 br_blue equ 09h
1 342 =000A br_green equ 0ah
Turbo Assembler Version 4.1 04/04/16 21:24:55 Page 7
calc.asm
1 343 =000B br_cyan equ 0bh
1 344 =000C br_red equ 0ch
1 345 =000D br_magenta equ 0dh
1 346 =000E yellow equ 0eh
1 347 =000F br_white equ 0fh
1 348
1 349 ; Constante pt tastatura folosind functiile DOS
1 350 ; Corespund cu valorile din tabelul ASCII
1 351 =0030 kbd_0 equ 30h
1 352 =0031 kbd_1 equ 31h
1 353 =0032 kbd_2 equ 32h
1 354 =0033 kbd_3 equ 33h
1 355 =0034 kbd_4 equ 34h
1 356 =0035 kbd_5 equ 35h
1 357 =0036 kbd_6 equ 36h
1 358 =0037 kbd_7 equ 37h
1 359 =0038 kbd_8 equ 38h
1 360 =0039 kbd_9 equ 39h
1 361
1 362 =002D kbd_minus equ 2dh
1 363 =002B kbd_plus equ 2bh
1 364 =002A kbd_inmultire equ 2ah
1 365 =002F kbd_impartire equ 2fh
1 366 =002E kbd_punct equ 2eh ; pune semn pt nr reale
1 367 =002D kbd_egal equ 2dh ; efectueaza operatia
1 368
1 369 =001B kbd_esc equ 1bh ; iese din program
1 370 =0020 kbd_spacebar equ 20h ; schimba semnul numarului
1 371 =0008 kbd_backspace equ 08h ; sterge o cifra
1 372 =000D kbd_enter equ 0dh ; efectueaza operatia
1 373
1 374 =0063 kbd_c_mic equ 63h ; sterge ecranul calculatorului
1 375 =0043 kbd_c_mare equ 43h ;
1 376 =0072 kbd_r_mic equ 72h ; operatia Radical
1 377 =0052 kbd_r_mare equ 52h ;
1 378 =0070 kbd_p_mic equ 70h ; numarul Pi
1 379 =0050 kbd_p_mare equ 50h ;
1 380 =0069 kbd_i_mic equ 69h ; 1/x - Inversul lui x
1 381 =0049 kbd_i_mare equ 49h ;
1 382 =0073 kbd_s_mic equ 73h ; x^2 - patratul lui x (Square)
1 383 =0053 kbd_s_mare equ 53h ;
1 384 =0062 kbd_b_mic equ 62h ; x^3 - cubul lui x (cuBe)
1 385 =0042 kbd_b_mare equ 42h ;
1 386
1 387 bios_write macro char, bg_color, fg_color, count
1 388 mov ah, 09h
1 389 mov al, char
1 390 mov bh, 00h
1 391 mov bl, bg_color * 16 + fg_color
1 392 mov cx, count
1 393 int 10h
1 394 endm
1 395
1 396 bios_cls macro
1 397 mov ax, 0600h
1 398 mov bh, 17h
1 399 mov dx,0
Turbo Assembler Version 4.1 04/04/16 21:24:55 Page 8
calc.asm
1 400 mov cx, 24 * 256 + 79
1 401 int 10h
1 402 endm
1 403
1 404 textmode80x25 macro
1 405 mov ax, 0003h
1 406 int 10h
1 407 endm
1 408
1 409 bios_data macro
1 410 mov ah, 0fh
1 411 int 10h
1 412 endm
1 413
1 414 start_video macro
1 415 push ax
1 416 push es
1 417 mov ax, 0b800h
1 418 mov es, ax
1 419 endm
1 420
1 421 end_video macro
1 422 pop es
1 423 pop ax
1 424 endm
1 425
1 426 ; Doar constante
1 427 cls macro bg_color, fg_color
1 428 xor di, di ; clear di, ES:DI points to video memory
1 429 mov ax, bg_color * 4096 + fg_color * 256
1 430 mov cx, 4000 ; amount of times to put it there
1 431 cld ; direction - forwards
1 432 rep stosw ; output character at ES:[DI]
1 433 endm
1 434
1 435 ; Doar constante
1 436 cls_region macro x1, y1, x2, y2, bg_color, fg_color, char
1 437 local @@again
1 438 mov bx, y1
1 439 @@again:
1 440 mov ax, 80
1 441 mul bx
1 442 add ax, x1
1 443 shl ax, 1
1 444 mov di, ax ;mov di, (y1 * 80 + x1) * 2; clear di, ES:DI points to video memory
1 445 mov ax, bg_color * 4096 + fg_color * 256 + char
1 446 mov cx, (x2 - x1 + 1)
1 447 cld ; direction - forwards
1 448 rep stosw ; output character at ES:[DI]
1 449 inc bx
1 450 cmp bx, y2
1 451 jng @@again
1 452 endm
1 453
1 454 ; [ES:DI] = [ES:(y * 80 + x) * 2]
1 455 bios_putc macro x, y, char
1 456 mov bx, y
Turbo Assembler Version 4.1 04/04/16 21:24:55 Page 9
calc.asm
1 457 mov ax, 80
1 458 mul bx
1 459 add ax, x
1 460 shl ax, 1
1 461 mov di, ax
1 462 mov al, char
1 463 stosb
1 464 endm
1 465
1 466 ; [ES:DI] = [ES:(y * 80 + x) * 2]
1 467 bios_putc_color macro x, y, char, bg_color, fg_color
1 468 mov bx, y
1 469 mov ax, 80
1 470 mul bx
1 471 add ax, x
1 472 shl ax, 1
1 473 mov di, ax
1 474 mov ax, bg_color * 4096 + fg_color * 256 + char
1 475 stosw
1 476 endm
1 477
1 478 ; o linie orizontala din caracterul 'char'
1 479 bios_hputc_color macro x, y, char, bg_color, fg_color, count
1 480 mov bx, y
1 481 mov ax, 80
1 482 mul bx
1 483 add ax, x
1 484 shl ax, 1
1 485 mov di, ax
1 486 mov ax, bg_color * 4096 + fg_color * 256 + char
1 487 mov cx, count
1 488 cld
1 489 rep stosw
1 490 endm
1 491
1 492 ; o linie verticala din caracterul 'char'
1 493 bios_vputc_color macro x, y, char, bg_color, fg_color, count
1 494 local @@again
1 495 mov bx, y
1 496 @@again:
1 497 mov ax, 80
1 498 mul bx
1 499 add ax, x
1 500 shl ax, 1
1 501 mov di, ax
1 502 mov ax, bg_color * 4096 + fg_color * 256 + char
1 503 stosw
1 504 inc bx
1 505 cmp bx, y+count-1
1 506 jng @@again
1 507 endm
1 508
1 509 ; Scriem un sir la pozitia x, y
1 510 bios_puts macro x, y, sir, bg_color, fg_color, count
1 511 local @@again, @@finish
1 512 lea si, sir
1 513 mov bx, y
Turbo Assembler Version 4.1 04/04/16 21:24:55 Page 10
calc.asm
1 514 mov ax, 80
1 515 mul bx
1 516 add ax, x
1 517 shl ax, 1
1 518 mov di, ax
1 519 mov ah, bg_color * 16 + fg_color
1 520 mov cx, count
1 521 cld
1 522 @@again:
1 523 cmp cx, 0
1 524 je @@finish
1 525 lodsb
1 526 stosw
1 527 dec cx
1 528 jmp @@again
1 529 @@finish:
1 530 endm
1 531
1 532 gotoxy macro x, y
1 533 mov ah, 02h
1 534 mov bh, 0
1 535 mov dh, y
1 536 mov dl, x
1 537 int 10h
1 538 endm
539 include string.h
1 540
1 541 extrn strlen_proc:far
1 542 extrn strcat_proc:far
1 543 extrn strchr_proc:far
1 544 extrn memset_proc:far
1 545 extrn strcmp_proc:far
1 546 extrn atof_proc:far
1 547
1 548 strlen macro s, len
1 549 lea di, s
1 550 call strlen_proc
1 551 mov [len], ax
1 552 endm
1 553
1 554 strcat macro dest, source
1 555 lea di, dest
1 556 lea si, source
1 557 call far ptr strcat_proc
1 558 endm
1 559
1 560 strchr macro s, c, gasit
1 561 lea si, s
1 562 mov ah, c
1 563 call far ptr strchr_proc
1 564 mov [gasit], al
1 565 endm
1 566
1 567 memset macro s, c, count
1 568 mov al, c
1 569 lea di, s
1 570 mov cx, count
Turbo Assembler Version 4.1 04/04/16 21:24:55 Page 11
calc.asm
1 571 call far ptr memset_proc
1 572 endm
1 573
1 574 ; pos din source
1 575 strpcat macro dest, source, pos
1 576 lea di, dest
1 577 lea si, source
1 578 add si, pos
1 579 call far ptr strcat_proc
1 580 endm
1 581
1 582 ; compara 2 siruri
1 583 strcmp macro cs, ct, gasit
1 584 lea si, cs
1 585 lea di, ct
1 586 call far ptr strcmp_proc
1 587 mov [gasit], ax
1 588 endm
1 589
1 590 ; str delete last character
1 591 strdlc macro source
1 592 local @@sfarsit
1 593
1 594 lea di, source
1 595 call far ptr strlen_proc
1 596 ; Daca sirul are lungimea 0, terminam operatia
1 597 cmp ax, 0
1 598 je @@sfarsit
1 599
1 600 ; Punem la sfarsitul sirului 0
1 601 lea si, source
1 602 add si, ax
1 603 dec si
1 604 mov byte ptr [si], 0
1 605 @@sfarsit:
1 606 endm
1 607
1 608 ; str delete zero
1 609 strdz macro source
1 610 local @@sfarsit, @@again, @@go_on, stiintific
1 611 .data
1 612 stiintific db 0
1 613 .code
1 614 strchr source, 'E', stiintific
1 615 cmp byte ptr [stiintific], 1
1 616 je @@sfarsit
1 617
1 618 lea di, source
1 619 call far ptr strlen_proc
1 620 ; Daca sirul are lungimea 0, terminam operatia
1 621 cmp ax, 0
1 622 je @@sfarsit
1 623
1 624 ; Punem la sfarsitul sirului 0
1 625 lea si, source
1 626 add si, ax
1 627 dec si
Turbo Assembler Version 4.1 04/04/16 21:24:55 Page 12
calc.asm
1 628 @@again:
1 629 cmp byte ptr [si], '.'
1 630 jne @@go_on
1 631 mov byte ptr [si], 0
1 632 jmp @@sfarsit
1 633 @@go_on:
1 634 cmp byte ptr [si], '0'
1 635 jne @@sfarsit
1 636 cmp ax, 1
1 637 je @@sfarsit
1 638 mov byte ptr [si], 0
1 639 dec si
1 640 dec ax
1 641 jmp @@again
1 642 @@sfarsit:
1 643 endm
644
645 ; lungime maxima sir
646 =0015 max equ 21
647
648 0000 .model large
649 0000 .stack 256
650 0000 .data
651 0000 0D 0A 00 newline db cr, lf, 0
652 0003 30 31 32 33 34 35 36 case db kbd_0, kbd_1, kbd_2, kbd_3, kbd_4, kbd_5, kbd_6
653 000A 37 38 39 2D 2B 2A db kbd_7, kbd_8, kbd_9, kbd_minus, kbd_plus, kbd_inmultire
654 0010 2F 2E 2D 0D db kbd_impartire, kbd_punct, kbd_egal, kbd_enter
655 0014 20 08 63 43 db kbd_spacebar, kbd_backspace, kbd_c_mic, kbd_c_mare
656 0018 72 52 70 50 db kbd_r_mic, kbd_r_mare, kbd_p_mic, kbd_p_mare
657 001C 69 49 73 53 db kbd_i_mic, kbd_i_mare, kbd_s_mic, kbd_s_mare
658 0020 62 42 db kbd_b_mic, kbd_b_mare
659 0022 001F cases dw $ - case
660 0024 070Dr 075Cr 07ABr + casejmp dw et_0, et_1, et_2, et_3, et_4, et_5, et_6
661 07FAr 0849r 0898r +
662 08E7r
663 0032 0936r 0985r 09D4r + dw et_7, et_8, et_9, et_minus, et_plus, et_inmultire
664 0B7Fr 0B35r 0BC9r
665 003E 0C13r 0A23r 0FE2r + dw et_impartire, et_punct, et_egal, et_enter
666 0FE2r
667 0046 0A92r 1001r dw et_spacebar, et_backspace
668 004A 1071r 1071r 0C5Dr + dw et_c_mic, et_c_mare, et_r_mic, et_r_mare
669 0C5Dr
670 0052 0D04r 0D04r 0DA9r + dw et_p_mic, et_p_mare, et_i_mic, et_i_mare
671 0DA9r
672 005A 0E66r 0E66r 0F21r + dw et_s_mic, et_s_mare, et_b_mic, et_b_mare
673 0F21r
674
675 ; maxim 16 cifre cu tot cu '.', fara '-'
676 0062 16*(00) rezultat db (max+1) dup(0)
677 0078 16*(00) temp db (max+1) dup(0)
678 008E ???? x dw ?
679
680 0090 0000 len dw 0
681 0092 2D 30 00 minus_zero db "-0", 0
682 0095 30 2E 00 zero_punct db "0.", 0
683 0098 30 00 zero db '0', 0
684 009A 31 00 unu db '1', 0
Turbo Assembler Version 4.1 04/04/16 21:24:55 Page 13
calc.asm
685 009C 32 00 doi db '2', 0
686 009E 33 00 trei db '3', 0
687 00A0 34 00 patru db '4', 0
688 00A2 35 00 cinci db '5', 0
689 00A4 36 00 sase db '6', 0
690 00A6 37 00 sapte db '7', 0
691 00A8 38 00 opt db '8', 0
692 00AA 39 00 noua db '9', 0
693 00AC 2E 00 punct db '.', 0
694 00AE 2D 00 minus db '-', 0
695 00B0 00 are_punct db 0 ; variabila bool daca avem . in rezultat
696 00B1 00 are_minus db 0 ; variabila bool daca avem - in rezultat
697 00B2 0000 zero_initial dw 0
698 00B4 0000 e_minus_zero dw 0
699 00B6 ???????? numar dd ? ; variabila float pe 32 biti
700 00BA 49 6E 74 72 6F 64 75+ eroare_sqrt db "Introdu un nr + !", 0
701 20 75 6E 20 6E 72 20+
702 2B 20 21 00
703 00CC 49 6D 70 61 72 74 69+ eroare_div0 db "Impartire la 0 !", 0
704 72 65 20 6C 61 20 30+
705 20 21 00
706 00DD 4E 41 4E 2D 6E 6F 74+ eroare_nan db "NAN-not a number", 0
707 20 61 20 6E 75 6D 62+
708 65 72 00
709 00EE 2B 49 6E 66 69 6E 69+ eroare_pinf db "+Infinit", 0
710 74 00
711 00F7 2D 49 6E 66 69 6E 69+ eroare_minf db "-Infinit", 0
712 74 00
713 0100 53 54 28 30 29 20 67+ eroare_gol db "ST(0) gol", 0
714 6F 6C 00
715 010A 44 65 6E 6F 72 6D 61+ eroare_dp db "Denormalizat +", 0
716 6C 69 7A 61 74 20 2B+
717 00
718 0119 44 65 6E 6F 72 6D 61+ eroare_dn db "Denormalizat -", 0
719 6C 69 7A 61 74 20 2D+
720 00
721
722 0128 ???????? nr1 dd ?
723 012C ???????? nr2 dd ?
724 0130 00 op db 0
725 0131 350637BD round dd 0.0000005 ; Pt rotunjire
726 0135 00 clear db 0
727
728 0136 358637BD minim dd 0.000001
729 013A 0000 status dw 0
730 013C .code
731 0000 start:
732 ; Initializam segmentele pt date si pt acces memorie text
733 init_ds_es
1 734 0000 50 push ax
1 735 0001 B8 0000s mov ax,dgroup
1 736 0004 8E D8 mov ds,ax
1 737 0006 8E C0 mov es,ax
1 738 0008 58 pop ax
739 0009 9B DB E3 finit
740
741 ; Intram in modul text 80x25
Turbo Assembler Version 4.1 04/04/16 21:24:55 Page 14
calc.asm
742 textmode80x25
1 743 000C B8 0003 mov ax, 0003h
1 744 000F CD 10 int 10h
745
746 start_video
1 747 0011 50 push ax
1 748 0012 06 push es
1 749 0013 B8 B800 mov ax, 0b800h
1 750 0016 8E C0 mov es, ax
751
752 ; Stergem tot ecranul
753 cls br_red, white
1 754 0018 33 FF xor di, di ; clear di, ES:DI points to video memory
1 755 001A B8 C700 mov ax, br_red * 4096 + white * 256
1 756 001D B9 0FA0 mov cx, 4000 ; amount of times to put it there
1 757 0020 FC cld ; direction - forwards
1 758 0021 F3> AB rep stosw ; output character at ES:[DI]
759
760 ; Fundalul calculatorului
761 cls_region 28, 1, 54, 23, br_white, black, 176
1 762 0023 BB 0001 mov bx, 1
1 763 0026 ??0000:
1 764 0026 B8 0050 mov ax, 80
1 765 0029 F7 E3 mul bx
1 766 002B 05 001C add ax, 28
1 767 002E D1 E0 shl ax, 1
1 768 0030 8B F8 mov di, ax ;mov di, (1 * 80 + 28) * 2; clear di, ES:DI points to video memory
1 769 0032 B8 F0B0 mov ax, br_white * 4096 + black * 256 + 176
1 770 0035 B9 001B mov cx, (54 - 28 + 1)
1 771 0038 FC cld ; direction - forwards
1 772 0039 F3> AB rep stosw ; output character at ES:[DI]
1 773 003B 43 inc bx
1 774 003C 83 FB 17 cmp bx, 23
1 775 003F 7E E5 jng ??0000
776
777 ; Fundalul unde se afiseaza rezultatul calculelor
778 cls_region 30, 3, 52, 5, white, black, 0
1 779 0041 BB 0003 mov bx, 3
1 780 0044 ??0001:
1 781 0044 B8 0050 mov ax, 80
1 782 0047 F7 E3 mul bx
1 783 0049 05 001E add ax, 30
1 784 004C D1 E0 shl ax, 1
1 785 004E 8B F8 mov di, ax ;mov di, (3 * 80 + 30) * 2; clear di, ES:DI points to video memory
1 786 0050 B8 7000 mov ax, white * 4096 + black * 256 + 0
1 787 0053 B9 0017 mov cx, (52 - 30 + 1)
1 788 0056 FC cld ; direction - forwards
1 789 0057 F3> AB rep stosw ; output character at ES:[DI]
1 790 0059 43 inc bx
1 791 005A 83 FB 05 cmp bx, 5
1 792 005D 7E E5 jng ??0001
793
794 ; < Randul 1 de operatori >
795 ; Cifra 7
796 cls_region 30, 7, 32, 9, br_cyan, black, 0
1 797 005F BB 0007 mov bx, 7
1 798 0062 ??0002:
Turbo Assembler Version 4.1 04/04/16 21:24:55 Page 15
calc.asm
1 799 0062 B8 0050 mov ax, 80
1 800 0065 F7 E3 mul bx
1 801 0067 05 001E add ax, 30
1 802 006A D1 E0 shl ax, 1
1 803 006C 8B F8 mov di, ax ;mov di, (7 * 80 + 30) * 2; clear di, ES:DI points to video memory
1 804 006E B8 B000 mov ax, br_cyan * 4096 + black * 256 + 0
1 805 0071 B9 0003 mov cx, (32 - 30 + 1)
1 806 0074 FC cld ; direction - forwards
1 807 0075 F3> AB rep stosw ; output character at ES:[DI]
1 808 0077 43 inc bx
1 809 0078 83 FB 09 cmp bx, 9
1 810 007B 7E E5 jng ??0002
811
812 ; Cifra 8
813 cls_region 34, 7, 36, 9, br_cyan, black, 0
1 814 007D BB 0007 mov bx, 7
1 815 0080 ??0003:
1 816 0080 B8 0050 mov ax, 80
1 817 0083 F7 E3 mul bx
1 818 0085 05 0022 add ax, 34
1 819 0088 D1 E0 shl ax, 1
1 820 008A 8B F8 mov di, ax ;mov di, (7 * 80 + 34) * 2; clear di, ES:DI points to video memory
1 821 008C B8 B000 mov ax, br_cyan * 4096 + black * 256 + 0
1 822 008F B9 0003 mov cx, (36 - 34 + 1)
1 823 0092 FC cld ; direction - forwards
1 824 0093 F3> AB rep stosw ; output character at ES:[DI]
1 825 0095 43 inc bx
1 826 0096 83 FB 09 cmp bx, 9
1 827 0099 7E E5 jng ??0003
828
829 ; Cifra 9
830 cls_region 38, 7, 40, 9, br_cyan, black, 0
1 831 009B BB 0007 mov bx, 7
1 832 009E ??0004:
1 833 009E B8 0050 mov ax, 80
1 834 00A1 F7 E3 mul bx
1 835 00A3 05 0026 add ax, 38
1 836 00A6 D1 E0 shl ax, 1
1 837 00A8 8B F8 mov di, ax ;mov di, (7 * 80 + 38) * 2; clear di, ES:DI points to video memory
1 838 00AA B8 B000 mov ax, br_cyan * 4096 + black * 256 + 0
1 839 00AD B9 0003 mov cx, (40 - 38 + 1)
1 840 00B0 FC cld ; direction - forwards
1 841 00B1 F3> AB rep stosw ; output character at ES:[DI]
1 842 00B3 43 inc bx
1 843 00B4 83 FB 09 cmp bx, 9
1 844 00B7 7E E5 jng ??0004
845
846 ; Impartire
847 cls_region 42, 7, 44, 9, br_cyan, black, 0
1 848 00B9 BB 0007 mov bx, 7
1 849 00BC ??0005:
1 850 00BC B8 0050 mov ax, 80
1 851 00BF F7 E3 mul bx
1 852 00C1 05 002A add ax, 42
1 853 00C4 D1 E0 shl ax, 1
1 854 00C6 8B F8 mov di, ax ;mov di, (7 * 80 + 42) * 2; clear di, ES:DI points to video memory
1 855 00C8 B8 B000 mov ax, br_cyan * 4096 + black * 256 + 0
Turbo Assembler Version 4.1 04/04/16 21:24:55 Page 16
calc.asm
1 856 00CB B9 0003 mov cx, (44 - 42 + 1)
1 857 00CE FC cld ; direction - forwards
1 858 00CF F3> AB rep stosw ; output character at ES:[DI]
1 859 00D1 43 inc bx
1 860 00D2 83 FB 09 cmp bx, 9
1 861 00D5 7E E5 jng ??0005
862
863 ; Numarul pi
864 cls_region 46, 7, 48, 9, br_cyan, black, 0
1 865 00D7 BB 0007 mov bx, 7
1 866 00DA ??0006:
1 867 00DA B8 0050 mov ax, 80
1 868 00DD F7 E3 mul bx
1 869 00DF 05 002E add ax, 46
1 870 00E2 D1 E0 shl ax, 1
1 871 00E4 8B F8 mov di, ax ;mov di, (7 * 80 + 46) * 2; clear di, ES:DI points to video memory
1 872 00E6 B8 B000 mov ax, br_cyan * 4096 + black * 256 + 0
1 873 00E9 B9 0003 mov cx, (48 - 46 + 1)
1 874 00EC FC cld ; direction - forwards
1 875 00ED F3> AB rep stosw ; output character at ES:[DI]
1 876 00EF 43 inc bx
1 877 00F0 83 FB 09 cmp bx, 9
1 878 00F3 7E E5 jng ??0006
879
880 ; Clear
881 cls_region 50, 7, 52, 9, yellow, black, 0
1 882 00F5 BB 0007 mov bx, 7
1 883 00F8 ??0007:
1 884 00F8 B8 0050 mov ax, 80
1 885 00FB F7 E3 mul bx
1 886 00FD 05 0032 add ax, 50
1 887 0100 D1 E0 shl ax, 1
1 888 0102 8B F8 mov di, ax ;mov di, (7 * 80 + 50) * 2; clear di, ES:DI points to video memory
1 889 0104 B8 E000 mov ax, yellow * 4096 + black * 256 + 0
1 890 0107 B9 0003 mov cx, (52 - 50 + 1)
1 891 010A FC cld ; direction - forwards
1 892 010B F3> AB rep stosw ; output character at ES:[DI]
1 893 010D 43 inc bx
1 894 010E 83 FB 09 cmp bx, 9
1 895 0111 7E E5 jng ??0007
896
897 ; < Randul 2 de operatori >
898 ; Cifra 4
899 cls_region 30, 11, 32, 13, br_cyan, black, 0
1 900 0113 BB 000B mov bx, 11
1 901 0116 ??0008:
1 902 0116 B8 0050 mov ax, 80
1 903 0119 F7 E3 mul bx
1 904 011B 05 001E add ax, 30
1 905 011E D1 E0 shl ax, 1
1 906 0120 8B F8 mov di, ax ;mov di, (11 * 80 + 30) * 2; clear di, ES:DI points to video memory
1 907 0122 B8 B000 mov ax, br_cyan * 4096 + black * 256 + 0
1 908 0125 B9 0003 mov cx, (32 - 30 + 1)
1 909 0128 FC cld ; direction - forwards
1 910 0129 F3> AB rep stosw ; output character at ES:[DI]
1 911 012B 43 inc bx
1 912 012C 83 FB 0D cmp bx, 13
Turbo Assembler Version 4.1 04/04/16 21:24:55 Page 17
calc.asm
1 913 012F 7E E5 jng ??0008
914
915 ; Cifra 5