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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
| ecrire macro char
lea dx,char
mov ah,9 ;macro qui ecrit une chaine
int 33
ecrire endm
positionne macro lig,col
mov dh, lig
mov dl, col
mov bh, 0
mov ah, 2 ;cursor position
int 10h
positiionne endm
clear_screen macro
pusha
mov ax, 0600h
mov bh, 0000_1111b ;macro qui efface l'ecran
mov cx, 0
mov dh, 24
mov dl, 79
int 10h
popa
clear_screen endm
;-----------------------------------------------------
donnee segment 'data'
new_line db 0Dh,0Ah, '$'
tiree db "-----------------------------------------------$"
mess0 db "merci de votre patience $"
mess1 db "entrer le dexieme nombre $"
demande db "entrer une expression numerique quelconque $"
ask db "appuyer sur 1 pour recalculer et sur 0 pour quitter $"
chaine db 100 dup(0)
tab1 db 100 dup(0)
tab2 db 100 dup(0)
tab1dec db 100 dup(0)
tab2dec db 100 dup(0)
tabinv db 100 dup(0)
tab1op db 100 dup(0)
tab2op db 100 dup(0)
tab1div db 100 dup(0)
tab2div db 100 dup(0)
tabresult db 100 dup(0)
operation db 0
operation2 db 0
moins db 0
inf db 0
egale db 0
decalage dw 0
read dw 0
test_multiplication dw 0
virgule1 dw 0
virgule2 dw 0
zero1 dw 0
zero2 dw 0
zero11 dw 0
zero22 dw 0
retenue dw 0
non_vir dw 0
vir dw 0
virdivision dw 0
dir dw 0
infzero dw 0
dir2 dw 0
sir dw 0
sir2 dw 1
bxr dw 0
axr dw 0
signe db 0
result dw 0
cxr dw 0
teste dw 0
dont_print db 0
donnee ends
;------------------------
sseg segment stack 'stack'
dw 20 dup(?)
sseg ends
;------------------------------------
cseg segment 'code'
start:
; set segment registers:
mov ax, donnee
mov ds, ax
mov es, ax
;------------------------------------
clear_screen
recalculer:positionne 0,0
ecrire tiree
ecrire new_line
ecrire demande
ecrire new_line
ecrire tiree
positionne 3,0
call remplit_chaine
ecrire new_line
mov si,0
call calcul
ecrire ask
call scan
cmp al,31h
jne finished
clear_screen
call initialise_tous
call initialise_variable
jmp recalculer
finished:
mov ah,1
int 21h
;--------------------------------------------------------
;************ les procedures utilisées*********************
;------------------------------------------------------------
;procedure qui scan un caractere
scan proc
mov ah,1
int 21h
ret
scan endp
;-------------------------------------------------------------
;procedure qui ecrit un caractere
printchar proc
mov dl,al
mov ah,2
int 21h
ret
printchar endp
;-------------------------------------------------------------
;procedure qui range la chaine dans tabchaine
remplit_chaine proc
mov si,0
rem:call scan
cmp al,0dh ;teste la touche enterer
je fin
mov chaine[si],al
inc si
jmp rem
fin:ret
remplit_chaine endp
;--------------------------------------------------------------
;procedure qui affiche la chaine situe dans tabchaine
ecrire_chaine proc
mov cx,si
ecr: mov al,chaine[si]
call printchar
inc si
loop ecr
ret
ecrire_chaine endp
;----------------------------------------------------------
initialise_tous proc
mov cx,100
mov di,0
mov al,0
tout_initialise:mov chaine[di],al
mov tab1[di],al
mov tab2[di],al
mov tab1dec[di],al
mov tab2dec[di],al
mov tab1op[di],al
mov tab2op[di],al
mov tabinv[di],al
mov tab1div[di],al
mov tab2div[di],al
mov tabresult[di],al
inc di
loop tout_initialise
ret
initialise_tous endp
;-----------------------------------------
initialise_variable proc
mov operation,0
mov operation2,0
mov moins,0
mov inf,0
mov egale,0
mov decalage,0
mov read, 0
mov test_multiplication,0
mov virgule1,0
mov virgule2,0
mov zero1,0
mov zero2,0
mov zero11,0
mov zero22,0
mov retenue,0
mov non_vir,0
mov vir,0
mov virdivision,0
mov dir,0
mov infzero,0
mov dir2,0
mov sir,0
mov sir2,1
mov bxr,0
mov axr,0
mov signe,0
mov result,0
mov cxr,0
mov teste,0
mov dont_print,0
ret
initialise_variable endp
;--------------------------------------------------------------
;proicedure qui affiche le contenu de tab1
print_tab1 proc
mov al,61
call printchar
mov di,99
cmp tab1[di],0fbh
je dont_write
mov al,tab1[di]
add al,30h ;afficher le signe
call printchar
dont_write:dec di
zero_al:cmp tab1[di-1],0fch
je ecriture_tab
cmp di,-1
je fin_ecriture
mov al,tab1[di]
cmp al,0
jne di_trouv:
dec di
jmp zero_al
di_trouv:add di,infzero
ecriture_tab:mov al,tab1[di]
add al,30h
call printchar
cmp di,0
je fin_ecriture
dec di
jmp ecriture_tab
fin_ecriture:mov di,sir2
sub di,2
ec: cmp chaine[di],0
je qq
mov al,chaine[di]
call printchar
inc di
jmp ec
qq: ret
print_tab1 endp
;--------------------------------------------------------------
;procedure qui initialise tab2 a 0
initialise2 proc
mov cx,99
mov di,0
cc2:mov tab2[di],0
inc di
loop cc2
ret
initialise2 endp
;---------------------------------------------------------------
;procedure qui initialise tab1 a 0
initialise proc
mov cx,99
mov di,0
initiali:mov tab1[di],0
inc di
loop initiali
ret
initialise endp
;---------------------------------------------------------------
;procedure qui donne le premir element non nul de tab1 et tab2
compare proc
mov di,99
supinf:cmp di,0
je rr
dec di
mov al,tab1[di]
cmp al,0
jne rr
cmp al,tab2[di]
je supinf
rr:add di,1
mov cxr,di
ret
compare endp
;---------------------------------------------------------------
;procedure qui donne l ordre de tab1 et tab2
compare2 proc
mov cx,99
mov di,98
kkk:mov al,tab1[di]
cmp al,tab2[di]
jl lower
ja above
dec di
loop kkk
mov egale,1
lower:mov inf,1
jmp qr
above:mov inf,0
qr:ret
compare2 endp
;---------------------------------------------------------------
find_di proc
mov di,98
search_di:cmp di,0
je di_found
mov al,tab1[di]
cmp al,0
jne di_found
dec di
jmp search_di
di_found:ret
find_di endp
;-----------------------------------------------------------------
;procedure qui fait le calcul en cours
calcul proc
calculer:mov si,sir2
dec si
mov di,si
com:mov al,chaine[si]
mov dir2,ax
and al,00110000b ;tester si c'est un nombre
cmp al,00110000b
jne test_virgule
mov al,chaine[si]
cwd
push ax
inc si
jmp com
test_virgule: mov ax,dir2
inc si
push ax
cmp al,2ch
je com
pop ax
empile_operation:
cmp al,0 ;sauvgarde l operation prochaine
jne sauv_operation
mov teste,1 ;et verifie si la chaine est terminer
sauv_operation:mov al,chaine[si-1]
mov operation,al
mov ax,si ;axr recoit la longueur
sub ax,di
mov axr,ax
mov read,ax ;de l operation en cours
inc si
mov cx,ax
dec cx ;range les l operande en cours
mov di,0 ;dans tab2
pop1: pop bx
sub bl,30h
mov tab2[di],bl
inc di
loop pop1
mov dir2,di
mov sir2,si
call elimin_virgule
;-----------------------------------choisir une operations
cmp operation2,0
jne non_verser
call verser
jmp suite
non_verser:mov di,99
cmp operation2,43
jne non_addition
cmp tab1[di],0fbh
jne soustr
call addition
jmp suite
non_addition:cmp operation2,45
jne non_sustraction
cmp tab1[di],0fbh
je soustr
call scan
call addition
jmp suite
soustr: call sustraction
non_sustraction:cmp operation2,42
jne non_multiplication
call multiplication
mov ax,1
mov test_multiplication,ax
non_multiplication:
cmp operation2,47
jne non_division
call division
;-----------------------------------------------------
non_division:
suite:
call initialise2
cmp test_multiplication,1
jne non_multip
mov ax,vir ;test multiplication pour virgule
mov bx,2
mul bx
mov vir,ax
non_multip:call withvirgule
mov test_multiplication,0 ;reinstialise
cmp dont_print,1
je dont_print_it
call print_tab1
dont_print_it:
mov dont_print,0
ecrire new_line
cmp teste,1 ;verifie si la chaine est terminer
je fin_calcul
mov al,operation
mov operation2,al
call initialise2
jmp calculer
fin_calcul:
ret
calcul endp
;---------------------------------------
;-----------procedures de calcul------
;---------------------------------------
elimin_virgule proc
mov di,0 ;on donne la position de virgule1
search_vir_tab1:mov al,tab1[di]
cmp al,0fch
je virgule_1op_found
inc di
cmp di,99
jne search_vir_tab1
mov ax,0
mov virgule1,ax
jmp recherche_zero_tab1
;--------------------------------------------------------------
virgule_1op_found:
mov virgule1,di
recherche_zero_tab1:
mov di,98
search_zero_tab1:cmp tab1[di-1],0fch
je zero_tab1_found
cmp di,0
je zero_tab1_found
; on donne zero1
cmp tab1[di],0
jne zero_tab1_found
dec di
jmp search_zero_tab1
zero_tab1_found:mov zero11,di
;----------------------------------------------------------
mov di,0 ;on donne la position de virgule2
search_vir_tab2:
mov al,tab2[di]
cmp al,0fch
je virgule_2op_found
inc di
cmp di,99
jne search_vir_tab2
mov ax,0
mov virgule2,ax
jmp recherche_zero_tab2
;--------------------------------------------------------------
virgule_2op_found:
mov virgule2,di
recherche_zero_tab2:
mov di,98
search_zero_tab2:cmp tab2[di-1],0fch
je zero_tab2_found
cmp di,0
je zero_tab2_found
; on donne zero2
cmp tab2[di],0
jne zero_tab2_found
dec di
jmp search_zero_tab2
zero_tab2_found:mov zero22,di
;-------------------------------------------------------------------------
jner:mov ax,virgule1 ;les positions apres la virgule est dans vir
mov bx,virgule2
cmp ax,bx
jl prend_virgule2
mov vir,ax
jmp carry_on
prend_virgule2: mov vir,bx
;---------------------------------------------------
carry_on:mov cx,99
mov di,0
mov al,0
initialis:mov tab1dec[di],al
mov tab2dec[di],al ;initialise les tt
inc di
loop initialis ;tab1dec et tab2dec
;--------------------------------------------------
cmp vir,0
je pas_de_virgule ;teste si il y a pas de virgule
;-------------------------------------------------------------
mov non_vir,0 ;ranger la parie decimal
;---------------------------------
mov ax,vir
cmp ax,virgule1 ;teste si vir est virgule1
jne on_met_zero_op1
;-------------------------------------------------
mov cx,vir
mov di,0 ;on push la virgule1
rang_vir_op1: mov al,tab1[di]
push ax
inc di
loop rang_vir_op1
;------------------------------------------
mov cx,vir
dec di
jmp rangdec1:
;---------------------------------------------
on_met_zero_op1: mov cx,vir
sub cx,virgule1 ;on range les zeros
mov di,0
rang_vir_op1_zero:mov al,0
push ax
inc di
loop rang_vir_op1_zero
;-----------------------------------------------
cmp virgule1,0
je pas_de_reste
mov dir,di
mov di,0
mov cx,virgule1
rang_rest_op1: mov al,tab1[di]
push ax
inc di ;on range le reste de virgule1
loop rang_rest_op1
add di,dir
jmp ranger_dans_tab1dec
pas_de_reste: mov non_vir,1
ranger_dans_tab1dec:
dec di
mov cx,vir ;on a ranger la partie decimale
rangdec1: pop ax
mov tab1dec[di],al
dec di
loop rangdec1
;----------------------------------------------------
mov cx,zero11 ;cx donne le nombre de nombre entieres
sub cx,virgule1
add cx,non_vir
mov si,vir ;si positionne le tab a ranger
inc si
mov di,virgule1
inc di ;di positionne le tab1
sub di,non_vir
rangent1: mov al,tab1[di]
push ax ;on a ranger la parie entiere
inc di
inc si
loop rangent1
;-------------------------------------------
mov cx,zero11
sub cx,virgule1
add cx,non_vir
;------------------------------------------
sub si,2
rangentp1: pop ax ;on range la partie entiere
mov tab1dec[si],al
dec si
loop rangentp1
;------------------------------------------------------------------------
; tab2
mov non_vir,0
mov ax,vir
cmp ax,virgule2 ;teste si vir est virgule2
jne on_met_zero_op2
;-------------------------------------------------
mov cx,vir
mov di,0 ;on push la virgule1
rang_vir_op2: mov al,tab2[di]
push ax
inc di
loop rang_vir_op2
;------------------------------------------
mov cx,vir
dec di
jmp rangdec2:
;---------------------------------------------
on_met_zero_op2: mov cx,vir
sub cx,virgule2 ;on range les zeros
mov di,0
rang_vir_op2_zero:mov al,0
push ax
inc di
loop rang_vir_op2_zero
;-----------------------------------------------
cmp virgule2,0
je pas_de_reste2
mov dir,di
mov di,0
mov cx,virgule2
rang_rest_op2: mov al,tab1[di]
push ax
inc di ;on range le reste de virgule2
loop rang_rest_op2
add di,dir
jmp ranger_dans_tab2dec
pas_de_reste2: mov non_vir,1
ranger_dans_tab2dec:
dec di
mov cx,vir ;on a ranger la partie decimale
rangdec2: pop ax
mov tab2dec[di],al
dec di
loop rangdec2
;----------------------------------------------------
mov cx,zero22 ;cx donne le nombre de nombre entieres
sub cx,virgule2
add cx,non_vir
mov si,vir ;si positionne le tab a ranger
inc si
mov di,virgule2
inc di ;di positionne le tab2
sub di,non_vir
rangent2: mov al,tab2[di]
push ax ;on a ranger la parie entiere
inc di
inc si
loop rangent2
;-------------------------------------------
mov cx,zero22
sub cx,virgule2
add cx,non_vir
;------------------------------------------
sub si,2
rangentp2: pop ax ;on range la partie entiere
mov tab2dec[si],al
dec si
loop rangentp2
;------------------------------------------------------------------------
mov non_vir,0
;-----------------------------------------------------------------------
mov cx,98
mov di,0
ikj: mov al,tab1dec[di]
mov bl,tab2dec[di]
mov tab1[di],al ;on copier les tableaux
mov tab2[di],bl
inc di
loop ikj
pas_de_virgule: ret
elimin_virgule endp
;----------------------------------------------------------
withvirgule proc
mov di,0 ;pas de virgule
cmp vir,0
je pas_virgule
kgf: cmp di,vir
je virgule_trouv
mov al,tab1[di]
mov tab2[di],al
inc di
jmp kgf
virgule_trouv:mov tab2[di],0fch
mov si,di
inc di
mov cx,98
sub cx,di
dec cx
mpo: mov al,tab1[si]
mov tab2[di],al
inc di
inc si
loop mpo
jmp fin_withvirgule
pas_virgule:mov cx,98
mov di,0
by:mov al,tab1[di]
mov tab2[di],al
inc di
loop by
fin_withvirgule: mov cx,98
mov di,0
rem_ta21:mov al,tab2[di]
mov tab1[di],al
inc di
loop rem_ta21
ret
withvirgule endp
;--------------------------------------------------
verser proc
mov di,99
mov tab1[di],0fbh
mov cx,read
mov di,0
ver: mov al,tab2[di]
mov tab1[di],al
inc di
loop ver
call compare
mov dont_print,1
ret
verser endp
;--------------------------------------------------------------
addition proc
mov di,0
mov cx,99
add cx,1
go: mov al,tab1[di]
add al,tab2[di]
cmp al,10
jnge nge
sub al,10
add tab1[di+1],1 ;retenu
nge: mov tab1[di],al
inc di
loop go
call compare
ret
addition endp
;------------------------------------------------
sustraction proc
call compare
sub di,1
push di
call compare2
pop di
cmp inf,1 ; verifie l ordre des operande ;si la premiere superieur on fait une saustraction normal ;si la seconde est superieure on les permutes et on fait
jne superieur ; la soustraction
jmp inferieur
inferieur: call compare ;permet d echanger le contenu
mov cx,cxr ; de tab1 et tab2
mov di,0 ;
xchge:mov al,tab1[di] ;
xchg al,tab2[di] ;
mov tab1[di],al ;
inc di
loop xchge
mov di,99
cmp tab1[di],0fdh
je positif
mov tab1[di],0fdh
jmp sustraire
positif: mov tab1[di],0fbh
jmp sustraire
superieur:mov di,99
cmp tab1[di],0fdh
jne positife
mov tab1[di],0fdh
jmp sustraire
positife: mov tab1[di],0fbh
sustraire: mov di,0
mov cx,cxr
sus: mov al,tab1[di]
cmp al,tab2[di] ;fait la sustraction entre tab1 et tab2
jae ae
add al,10
add tab2[di+1],1
ae:sub al,tab2[di]
mov tab1[di],al
inc di
loop sus
ret
sustraction endp
;---------------------------------------------------------------------
multiplication proc
mov retenue,0
call find_di
mov dir,di
add dir,2
mov si,98
ver_zero2: cmp si,0
je find_si
mov al,tab2[si]
cmp al,0
jne find_si
dec si
jmp ver_zero2
find_si: mov sir,si
add sir,2
mov cx,98
mov di,0
range:mov al,tab1[di] ;range les deux operandes dans les tableaux
mov bl,tab2[di] ;tab1op et tab2op
mov tab1op[di],al
mov tab2op[di],bl
inc di
loop range
call initialise
mov decalage,0
mov si,0 ;iterations de premiere operande
mult: call initialise2
mov di,0 ;si deuxieme opereande
multip: mov al,tab2op[si]
mul tab1op[di]
add ax,retenue
mov bl,10 ;extraire
div bl ;mod et div
;-------------------------------------------------------------------------
push di
add di,decalage ;decalage
mov tab2[di],ah
pop di
;---------------------------------------------------------
and ax,0000000011111111b ;extraire al
mov retenue,ax
inc di
cmp di,dir
je fin_mul_1chiffre
jmp multip
;--------------------------------------------------
fin_mul_1chiffre:add decalage,1
call addition ;additione tab2 avec l ancien resultat
call initialise2 ;resultat dans tab1
inc si
cmp si,sir
je fin_multiplication
mov retenue,0
jmp mult
fin_multiplication:
ret
multiplication endp
;-------------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------------
division proc
mov si,0
mov di,99
mov al,tab1[di]
mov signe,al
mov cx,99 ;copier tab1 dans tab2div
mov di,98
coo: mov al,tab1[di]
mov tab2div[di],al
dec di
loop coo
;--------------------------------------------
mov di,99
nnn:cmp tab2div[di],0
jne dirsave ;on donne di
dec di
jmp nnn
dirsave:mov dir,di
;---------------------------------------------
mov egale,0
call compare2 ;teste si les deux operations sont equivalentes
cmp egale,1
mov axr,-1
je elles_sont_equivalentes
;------------------------------------------
mov al,0
mov axr,-1
mov infzero,1
cmp inf,1 ;teste si la premiere operation est inferieure à la dexieme
je zeero
mov infzero,0
call initialise
;--------------------------------------
mov di,dir
mov axr,di ;axr indique la fin de la parite entiere
sub axr,2
;--------------------------------------------------
mov cx,1
mov cxr,cx
rangetab1: mov di,dir
mov cx,cxr
www: mov al,tab2div[di]
and ax,0000000011111111b
push ax
dec di
loop www
mov axr,di
mov bxr,di
mov cx,cxr
mov di,0 ;extraire les premiers chiffres
tab1ran: pop ax
mov tab1[di],al
inc di
loop tab1ran
push cxr
call compare2
pop cxr
cmp egale,1
je supe
cmp inf,1
jne supe
inc cxr
jmp rangetab1
;------------------------------------------------
divis:
supe:
call compare2
cmp inf,1
mov al,0 ;teste si la premiere operation est inferieure à la dexieme
je zeero
push si
call find_di
mov si,98
qaze_si:mov al,tab2[si]
cmp al,0
jne zed_si
dec si
jmp qaze_si
zed_si:
mov al,9
mov bl,tab1[di]
cmp bl,tab2[si]
je sont_egaux
;/---------------------------------------------------
mov al,tab1[di] ;diviser premir chiffre
cmp al,tab2[si]
jae gg
mov bl,10
mul bl
mov bl,tab1[di-1]
and bx,000000001111111b
add ax,bx
gg: cbw
mov bl,tab2[si]
div bl
and ax,0000000011111111b
sont_egaux: pop si
zeero: mov tabresult[si],al ;range le resultat de 1 division dans tab1
;----------------------------------------------------------
mov di,0
mov cx,98
nnl: mov al,tab1[di] ;deplacer tab1 dans tab1div
mov tab1div[di],al
inc di
loop nnl
;----------------------------------------------------------
push ax
call initialise
pop ax
insatisfait:mov di,0 ;multipie le resultat avec la dexime operande
mov al,tabresult[si]
mov tab1[di],al
push si
call multiplication
pop si
;--------------------------------------------------------
mov cx,99
mov di,0
tt: mov al,tab1div[di] ; range dans tab2 le resultat
mov tab2[di],al
inc di
loop tt
;-------------------------------------------------------
call compare2
cmp inf,1 ;teste si le resultat de division est satisfait
je bonn ;sinon en decriment le resultat
mov al,tabresult[si]
sub al,1
mov tabresult[si],al
call initialise
;--------------------------------------------------------
mov cx,cxr
mov di,0
tt2:mov al,tab2op[di] ; range dans tab2 la dexieme operande
mov tab2[di],al
inc di ; pour faire la soustraction
loop tt2
jmp insatisfait
;-----------------------------------------------------
bonn: call sustraction
;-----------------------------------------------------
call find_di
mov cx,di
inc cx ;descendre un neauvaux chiffre
mov di,axr ;contiet le nouveaux chiffre
cmp axr,-1
jnle partie_entiere
mov al,0
inc virdivision
jmp continue_faire
partie_entiere:mov al,tab2div[di]
continue_faire:mov di,0
mov tab1div[di],al
hhh: mov al,tab1[di]
inc di
mov tab1div[di],al
loop hhh
dec axr ;teste si la division est terminer
cmp virdivision,8
je finnn
;--------------------------------------------
inc di
yyyy:
mov tab1div[di],0
cmp di,98
je za
inc di ;mettre a zero les autres chiffres
jmp yyyy
;-------------------------------------------------
za: mov cx,99
inc cx
mov di,0
ttt2:mov al,tab1div[di] ; range dans tab1 la 1 operande
mov bl,tab2op[di]
mov tab1[di],al
mov tab2[di],bl
inc di
loop ttt2
inc si
inc result
jmp divis
finnn:dec virdivision
;----------------------------------------------
call initialise
mov di,99
mov al,signe
mov tab1[di],al ;copier tabresult dans tab1
mov cx,98
mov di,0
cccc: mov al,tabresult[di]
mov tab1[di],al
inc di
loop cccc
call compare
;----------------------------------------------
mov di,result
mov dir,di
mov cx,di
inc cx
push_:mov al,tab1[di]
push ax
dec di
loop push_
mov di,dir
mov cx,di
inc cx
pop_:pop ax
mov tab1[di],al
dec di
loop pop_
;--------------------------------------------
jmp continuer
elles_sont_equivalentes:
call initialise
mov di,0
mov tab1[di],1
jmp normale
continuer: mov ax,virdivision
mov vir,ax
normale:ret
division endp
ends
end start |
Partager