goldenprincess

حاسبة بلغة الاسمبلي

5 ردود في هذا الموضوع

السلام عليكم ورحمة الله وبركاته

اتمنى من حضرتكم مساعدتي في تصميم برنامج اله حاسبة يقوم بالعمليات الاساسية (/ * - +) فقط بلغة الاسمبلي assembleur للمعالج((emu8086(32bits))

حيث يدخل المستخدم الصيغة التي يود حسابها مثلا 2+3-4 و البرنامج يظهر النتيجة (لا يشترط احترام الاولوية في العمليات الحسابية )

فارجو ممن يستطيع تقديم المساعدة الا يبخل علي بها

ولكم جزيل الشكر والاحترام

-1

شارك هذا الرد


رابط المشاركة
شارك الرد من خلال المواقع ادناه

السلام عليكم،

حاول اولا في برنامج و إن واجهت مشكلة مستعصية، ضعها هنا و نحن نساعدك.

1

شارك هذا الرد


رابط المشاركة
شارك الرد من خلال المواقع ادناه

انا حاولت انجز الحاسبة بلعة الاسمبلي و هي تعمل بشكل جيد لكن فيها بعض المشاكل الصغيرة فهي تعطي نتيجة خاطئة ادا قسمنا 12 على 1 ،11 على 1 و 10 على 1 و ايضا ادا كتبنا 4+8- لا تعطي نتيجة في حين ادا كتبنا 8-4 يعطي النتيجة صحيحة 4-

لمن يستطيع ان يحدد لي الخطأ و يصححه لا يبخل علي شكراا

استعملت (emu8086 32bt)

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

1

شارك هذا الرد


رابط المشاركة
شارك الرد من خلال المواقع ادناه

السلام عليكم،

أخي لو بحثت قليلا في مجلدات البرنامج emu8086 لوجدت الحل. هناك مثال لآلة حاسبة و هي تفي بالغرض.


X:\Path\emu8086\exemples\calculator.asm

لحل مشكلة عملية الجمع، استعمل الدالة do_plus:


do_plus proc

mov ax, num1
add ax, num2
call print_num ; print ax value.
ret

do_plus endp

لحل مشكلة عملية القسمة، اليك الدالة do_div:


do_div proc

; dx is ignored (calc works with tiny integer numbers only).
mov dx, 0
mov ax, num1
idiv num2 ; ax = (dx ax) / num2.
cmp dx, 0
jnz approx
call print_num ; print ax value.
jmp return

approx:
call print_num ; print ax value.
lea dx, smth ; smth contains " and something....$" string
mov ah, 09h ; output string at ds:dx
int 21h

return:
ret

do_div endp

دوال الطباعة:


; this procedure prints number in AX,
; used with PRINT_NUM_UNS to print unsigned numbers:
PRINT_NUM PROC NEAR
PUSH DX
PUSH AX

CMP AX, 0
JNZ not_zero

PUTC '0'
JMP printed

not_zero:
; the check SIGN of AX,
; make absolute if it's negative:
CMP AX, 0
JNS positive
NEG AX

PUTC '-'

positive:
CALL PRINT_NUM_UNS
printed:
POP AX
POP DX
RET
PRINT_NUM ENDP


; this procedure prints out an unsigned
; number in AX (not just a single digit)
; allowed values are from 0 to 65535 (FFFF)
PRINT_NUM_UNS PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX

; flag to prevent printing zeros before number:
MOV CX, 1

; (result of "/ 10000" is always less or equal to 9).
MOV BX, 10000 ; 2710h - divider.

; AX is zero?
CMP AX, 0
JZ print_zero

begin_print:

; check divider (if zero go to end_print):
CMP BX,0
JZ end_print

; avoid printing zeros before number:
CMP CX, 0
JE calc
; if AX<BX then result of DIV will be zero:
CMP AX, BX
JB skip
calc:
MOV CX, 0 ; set flag.

MOV DX, 0
DIV BX ; AX = DX:AX / BX (DX=remainder).

; print last digit
; AH is always ZERO, so it's ignored
ADD AL, 30h ; convert to ASCII code.
PUTC AL


MOV AX, DX ; get remainder from last div.

skip:
; calculate BX=BX/10
PUSH AX
MOV DX, 0
MOV AX, BX
DIV CS:ten ; AX = DX:AX / 10 (DX=remainder).
MOV BX, AX
POP AX

JMP begin_print

print_zero:
PUTC '0'

end_print:

POP DX
POP CX
POP BX
POP AX
RET
PRINT_NUM_UNS ENDP

ملاحظة:

-استعمل تنسيقات الكود عند ارفاقك كود داخل الموضوع

-مصدر هذه الدوال مثال الآلة الحاسبة المرفق مع برنامج المحاكاة emu8086

-لا تنسى تعريف متغير DW جديد باسم "ten" (مستعمل في الدالة PRINT_NUM_UNS)

-أي استفسار، يمكنك الرجوع لهذا الموضوع و طرجه هنا

0

شارك هذا الرد


رابط المشاركة
شارك الرد من خلال المواقع ادناه

1+ للمحاولة في البرنامج ;)

0

شارك هذا الرد


رابط المشاركة
شارك الرد من خلال المواقع ادناه

  • يستعرض القسم حالياً   0 members

    لا يوجد أعضاء مسجلين يشاهدون هذه الصفحة .