11
1. Să se realizeze un program care, calculează adunarea, scăderea, înmulţirea şi împărţirea a două numere, iar rezultatul să se pune în memoria RAM. Varianta 1: org 100h mov cx, 500h mov ds,cx mov ax,5 mov dx,2 add ax,dx ;aduna cele doua numere si suma pune in ax mov bx,50h mov [bx],ax ;rezultatul se pune in memorie la randul 50h mov ax,5 sub ax,dx ;scade din ax bx-ul si pune in ax mov bx, 52h mov [bx],ax mov ax,5 mul dx ;inmulteste cele doua numere mov bx,54h mov [bx],ax mov ax,5 mov cx,2 div cx ;imparte cele doua numere mov bx,56h mov [bx],ax ;in ax este catul mov bx,58h mov [bx],dx ;in dx se afla restul hlt 2. Să se realizeze un program care adună două numere care se găsesc în memoria RAM la adresele 500h:0h şi 501h:0h, iar rezultatul îl pune la adresa 502h:0h. org 100h mov ax,500h mov ds,ax mov cx,7 mov bx,0 mov [bx],cx mov dx,3 mov ax,501h mov ds,ax mov bx,0 mov [bx],dx add cx,dx mov ax,502h mov ds,ax mov bx,0 mov [bx],cx hlt 3. Să se realizeze un program care înmulţeşte două numere care se găsesc în memoria RAM la adresele 500h:0h şi 501h:0h, iar rezultatul se pune în 502h:0h. org 100h mov ax,500h mov ds,ax mov ax,7 mov bx,0 mov [bx],ax 1

Exercitii in EMU8086

Embed Size (px)

DESCRIPTION

Exercitii rezolvate in pentru Arhitectura Calculatoarelor(AC)

Citation preview

Page 1: Exercitii in EMU8086

1. Să se realizeze un program care, calculează adunarea, scăderea, înmulţirea şi împărţirea a două numere, iar rezultatul să se pune în memoria RAM.

Varianta 1:org 100hmov cx, 500hmov ds,cx

mov ax,5mov dx,2add ax,dx ;aduna cele doua numere si suma pune in ax

mov bx,50hmov [bx],ax ;rezultatul se pune in memorie la randul 50h

mov ax,5sub ax,dx ;scade din ax bx-ul si pune in ax

mov bx, 52hmov [bx],ax

mov ax,5mul dx ;inmulteste cele doua numere

mov bx,54hmov [bx],ax

mov ax,5mov cx,2div cx ;imparte cele doua numere

mov bx,56hmov [bx],ax ;in ax este catul

mov bx,58hmov [bx],dx ;in dx se afla restul

hlt

2. Să se realizeze un program care adună două numere care se găsesc în memoria RAM la adresele 500h:0h şi 501h:0h, iar rezultatul îl pune la adresa 502h:0h.

org 100h

mov ax,500hmov ds,ax

mov cx,7

mov bx,0mov [bx],cx

mov dx,3

mov ax,501hmov ds,ax

mov bx,0mov [bx],dx

add cx,dx

mov ax,502hmov ds,ax

mov bx,0mov [bx],cx

hlt

3. Să se realizeze un program care înmulţeşte două numere care se găsesc în memoria RAM la adresele 500h:0h şi 501h:0h, iar rezultatul se pune în 502h:0h.

org 100h

mov ax,500hmov ds,ax

mov ax,7

mov bx,0mov [bx],ax

mov cx,ax

mov dx,3 mov ax,501hmov ds,ax

mov bx,0mov [bx],dx mov ax,502hmov ds,ax

mov ax,cx mul dx

mov bx,0mov [bx],ax

hlt

1

Page 2: Exercitii in EMU8086

4. Să se realizeze un program care împarte două numere care, se găsesc în memoria RAM la adresele 500h:0h şi 501h:0h iar, câtul îl pune la adresa 502h:0h şi restul în 503h:0h

org 100h

mov ax,500hmov ds,ax

mov ax,7 mov [0],ax

mov bx,ax

mov ax,501hmov ds,ax

mov cx,2mov [0],cx

mov ax,502hmov ds,ax

mov ax,bx

div cx mov [0],ax

mov ax,503hmov ds,ax

mov [0],dx

hlt

5. Să se realizeze un program care, să calculeze n! punând rezultatele parţiale în memoria RAM, începând de la adresa 500h:0h.

org 100h

mov ax,500hmov ds,ax

mov ax,1mov cx,5

eticheta:

mul cx mov [bx],ax add bx,1 loop eticheta

hlt

6. Să se realizeze un program care calculează a^n , punând rezultatele parţiale în memoria RAM, începând de la adresa 500h:0h.

org 100h mov ax,500hmov ds,ax

mov ax,1mov cx,4

mov bx,0

eticheta:

mov dx,2 mul dx mov [bx],ax add bx,2 loop eticheta

hlt

2

Page 3: Exercitii in EMU8086

7. Să se realizeze un program care pune primele 10 numere pare în memoria RAM, începând de la adresa 500h:0h.

org 100h;vom tine minte in bx numarul de numere pare gasite (initial 0);atat timp cat bx != 10 se verifica numarul urmator;in ax vom tine minte numarul curent(la care suntem - pe care il verificam daca este par sau nu);daca div 2 genereaza un dx=0 atunci numarul este par si il vom pune in memorie la adresa 500+bx si bx va creste cu 1

mov ax, 0 ;numarul initial pe care il verific.

mov bx, 0 ;numarul de numere pare gasite

verificare:

mov cx, ax;

mov dx, 500hadd dx, bxmov ds, dx

mov dx, 0mov bx, 2div bx; impartim pe ax la bx=2 pentru a afla restul(dx)

care daca e 0 inseamna ca numarul ax e par

acum ca am folosit bx-ul la imparitre va trebui sa punem in bx din nou valoarea initiala bx = ds-500h

mov bx, dssub bx, 500h ;in continuare bx-ul va reprezenta din nou

numarul de numere pare gasite

cmp dx, 1jz nu_e_par

mov [0], cxadd bx, 1 ;vom creste numarul de numere pare gasite cu o

unitate. pentru ca am mai gasit un numar par

nu_e_par:

mov ax, cx

add ax, 1cmp bx, 10jz exitjmp verificare

exit:hlt

8. Să se realizeze un program care pune primele 10 numere impare în memoria RAM, începând de la adresa 500h:0h.

org 100hmov ax, 0mov bx, 0verificare:

mov cx, ax

mov dx, 500hadd dx, bxmov ds, dx

mov dx, 0mov bx, 2div bx

mov bx, dssub bx, 500h

cmp dx, 0jz e_par

mov [0], cxadd bx, 1

e_par:

mov ax, cx

add ax, 1jz exitjmp verificare

exit:hlt

9. Să se calculeze unde ai sunt elemnetele pare ale unui vector de numere naturale.

mov ax, 501hmov ds, axmov [0], 8

mov ax, 502hmov ds, axmov [0], 1

mov ax, 503h

mov ds, axmov [0], 0

mov ax, 504hmov ds, axmov [0], 5

mov ax, 505hmov ds, ax

3

Page 4: Exercitii in EMU8086

mov [0], 2

mov ax, 506hmov ds, axmov [0], 1

mov ax, 507hmov ds, axmov [0], 3

mov ax, 508hmov ds, axmov [0], 6

mov ax, 509hmov ds, axmov [0], 1

mov ax, 50Ahmov ds, axmov [0], 0

mov bx, 0mov cx, 10

citesteDinVector:

mov ax, 500hadd ax, cx mov ds, ax

mov ax, [0] mov cx, 2

div cxcmp dx, 1;

jz nuEPar

add bx, [0]

nuEPar:

mov cx, dssub cx, 500h

loop citesteDinVector

hlt

10. Să se calculeze ,unde bi sunt elementele impare ale unui vector de numere naturale.

mov ax, 501hmov ds, axmov [0], 8

mov ax, 502hmov ds, axmov [0], 1

mov ax, 503hmov ds, axmov [0], 0

mov ax, 504hmov ds, axmov [0], 5

mov ax, 505hmov ds, axmov [0], 2

mov ax, 506hmov ds, axmov [0], 1

mov ax, 507hmov ds, axmov [0], 5

mov ax, 508hmov ds, axmov [0], 6

mov ax, 509hmov ds, axmov [0], 1

mov ax, 50Ahmov ds, axmov [0], 5

mov ax, 1mov cx, 10

citesteDinVector:

mov bx, ax;trebuie sa verificam daca elementul este par. Pentru asta il

vom imparti la 2 si vom analiza restul;dar mai intai voi seta coloana(DS) pentru a citi din memorie. Sa zicem ca citesc de la 501h:0h

mov ax, 500hadd ax, cxmov ds, ax ;am setat coloana

mov ax, [0] ;pune in ax elementul de la coloana specificata si linia 0h

mov cx, 2div cx mov ax, bx;acum trebuie sa compar restul impartirii(dx) cu 0 daca sunt

egale inseamna ca elementul este parcmp dx, 0jz ePar

;Dar elementul meu care a fost citit mai devreme (in ax) s-a pierdut ... deci il voi citi iarasi din memorie(DS(coloana) e aceeasi)

mul [0]; inmulteste la ax pe bx elementul de la coloana specificata si linia 0h ... adica elementul nostru impar

ePar:mov cx, dssub cx, 500h

loop citesteDinVector

4

Page 5: Exercitii in EMU8086

hlt

11. Fiind daţi doi vectori An, Bn aparţinând lui N. Să se schimbe elementele vectorilor între ele (ai - bi şi bi – ai)

;crearea primului vectormov ax, 501hmov ds, axmov [0], 8

mov ax, 502hmov ds, axmov [0], 1

mov ax, 503hmov ds, axmov [0], 0

mov ax, 504hmov ds, axmov [0], 5

mov ax, 505hmov ds, axmov [0], 2

mov ax, 506hmov ds, axmov [0], 1

mov ax, 507hmov ds, axmov [0], 5

mov ax, 508hmov ds, axmov [0], 6

mov ax, 509hmov ds, axmov [0], 1

mov ax, 50Ahmov ds, axmov [0], 5

;crearea celui de-al doilea vectormov ax, 501hmov ds, axmov [2], 5

mov ax, 502hmov ds, axmov [2], 1

mov ax, 503hmov ds, ax

mov [2], 2

mov ax, 504hmov ds, axmov [2], 8

mov ax, 505hmov ds, axmov [2], 4

mov ax, 506hmov ds, axmov [2], 7

mov ax, 507hmov ds, axmov [2], 2

mov ax, 508hmov ds, axmov [2], 6

mov ax, 509hmov ds, axmov [2], 2

mov ax, 50Ahmov ds, axmov [2], 9

mov cx, 10

schimbaValorile:

;deci va trebui sa schimbam valorile intre 500+cx:0 cu 500+cx:2 ;unde 500 reprezinta inceputul vectorului si cx al catelea element din vector

;mai intai sa setam DS-ul (numarul coloanei)mov ax, 500hadd ax, cxmov ds, ax

mov ax, [0]

mov bx, [2] ;pune in bx elementul de pe randul 2

mov [0], bx ;pune pe randul 0 elementul din bx(adica cel care era initial pe randul 2)

mov [2], ax ;pune pe randul 2 elementul din ax (adica cel

care a fost initial pe randul 0)

loop schimbaValorilehlt

5

Page 6: Exercitii in EMU8086

12. Se dau următoarele elemente ale unui vector care începe de la adresa 500h:0h. (1,3,6,7,9,0). Să se realizeze un program care determină numărul de elemente pare ale vectorului.

mov ax, 500hmov ds, axmov [0], 1

mov ax, 501hmov ds, axmov [0], 3

mov ax, 502hmov ds, axmov [0], 6

mov ax, 503hmov ds, axmov [0], 7

mov ax, 504hmov ds, axmov [0], 9

mov ax, 505hmov ds, axmov [0], 0

mov bx, 0mov cx, 6;numarul de elemente din vector este 6

urmatorulElement:

mov ax, 500hadd ax, cxsub ax, 1mov ds, ax

mov ax, [0] ;pune in ax elem. de pe pozitia cx din vector

mov cx, bxmov bx, 2div bx;acum ca am terminat cu bx pot sa pun in el din nou

numarul de elemente pare gasitemov bx, cx

cmp dx, 1jz eImpar

add bx, 1

eImpar:

mov cx, dssub cx, 500hadd cx, 1

loop urmatorulElementhlt

13. Se dau următoarele elemente ale unui vector care începe de la adresa 500h:0h. (1,3,6,7,9,0). Să se realizeze un program care determină numărul de elemente impare ale vectorului.

mov ax, 500hmov ds, axmov [0], 1

mov ax, 501hmov ds, axmov [0], 3

mov ax, 502hmov ds, axmov [0], 6

mov ax, 503hmov ds, axmov [0], 7

mov ax, 504hmov ds, axmov [0], 9

mov ax, 505hmov ds, axmov [0], 0

mov bx, 0mov cx, 6

urmatorulElement:

mov ax, 500hadd ax, cxsub ax, 1mov ds, ax

mov ax, [0]mov cx, bxmov bx, 2div bxmov bx, cx

cmp dx, 0

jz eParadd bx, 1

ePar:

mov cx, dssub cx, 500hadd cx, 1

loop urmatorulElement

hlt

6

Page 7: Exercitii in EMU8086

14. Să se realizeze un program, care încarcă elementele unui vector cu valoarea 10h.

mov cx, 10urmatoareaCelula:

mov ax, 500hadd ax, cxmov ds, ax

mov [0], 10h

loop urmatoareaCelulahlt

15. Să se realizeze un program care încarcă elementele unei matrice de 4x4 cu valoarea de 10h.

org 100h

mov cx,4

prog: mov ax,500h mov ds,ax mov dx,cx mov cx,4 prog2: mov bx,dx

mov [bx],'A' add ax,1 mov ds,ax loop prog2 mov cx,dx loop prog

hlt

16. Să se realizeze un program care, calculează suma elementelor de pe diagonala principală a unei matrice.

org 100hmov bx,0

rowloop:

mov cx,0 mov ds,cx colloop: mov [bx],2 add cx,1 mov ds, cx cmp cx,10 jz goBackTorowloop jmp colloop goBackTorowloop: add bx,1 cmp bx,10

jz goOn: jmp rowloop goOn: mov dx,0 mov bx,0 diagonala: mov ds,bx mov al, [bx] add dx,ax add bx,1 cmp bx,10 jz exit: jmp diagonala exit:hlt

7

Page 8: Exercitii in EMU8086

17. Să se realizeze un program care înmulţeşte un vector cu un număr.

mov ax, 501hmov ds, axmov [0h], 1

mov ax, 502hmov ds, axmov [0h], 2

mov ax, 503hmov ds, axmov [0h], 3

mov ax, 504hmov ds, axmov [0h], 4

mov ax, 505hmov ds, axmov [0h], 5

mov ax, 506hmov ds, axmov [0h], 6

mov ax, 507h

mov ds, axmov [0h], 7

mov ax, 508hmov ds, axmov [0h], 8

mov cx, 8element:

;fiecare element va trebui sa fie citit, inmultit cu numarul, si pus la loc; pentru ca inmultirea se face la ax vom pune elementul din memorie tocmai in ax; apoi vom da mul pentru a fi inmultit si il vom pune la loc

mov ax, 500hadd ax, cxmov ds, ax

mov ax, [0h]mov bx, 2mul bx;si acum punem valoarea din ax inapoi in vectormov [0h], ax

loop elementhlt

18. Să se realizeze un program care înmulţeşte o matrice cu un număr.

mov ax, 501hmov ds, axmov [1h], 1

mov ax, 502hmov ds, axmov [1h], 2

mov ax, 503hmov ds, axmov [1h], 3

mov ax, 501hmov ds, axmov [2h], 4

mov ax, 502hmov ds, axmov [2h], 5

mov ax, 503hmov ds, axmov [2h], 6

mov ax, 501hmov ds, axmov [3h], 7

mov ax, 502hmov ds, axmov [3h], 8

mov ax, 503hmov ds, axmov [3h], 9

mov cx, 3; pentru ca matricea are 3 linii

linie:mov bx, cxmov cx, 3; pentru ca matricea are 3 coloane

coloana:

mov ax, 500hadd ax, cxmov ds, axmov ax, 0 ;pentru ca avem de gand sa lucram

cu al trebuie sa golim ah deci vom goli tot ax si vom seta apoi almov al, [bx] ; pune in al numarul din matrice

de la coloana DS si linia bx ... folosim al pentru a citi un numar pe 16

mov dx, 9; 9 este nr cu care inmultim matricea

mul dx

mov [bx], al

loop coloana

mov cx, bx

loop linie

hlt

8

Page 9: Exercitii in EMU8086

19. Să se realizeze un program care determină câte elemente nule se găsesc în zona de memorie RAM cuprinsă între adresele 500h:0h şi 509h:9h.

mov ax, 0mov cx, 9 ;pentru ca matricea noastra are 9 linii

linie:

mov bx, cxmov cx, 9; pentru ca matricea noastra are 9 coloane

coloana:

mov dx, 500hadd dx, cxsub dx, 1mov ds, dx

cmp [bx], 0

jz e0

jmp nuE0

e0:add ax, 1

nuE0:

loop coloanamov cx, bx

loop linie

hlt

20. Să se realizeze un program care copiază o zonă de memorie RAM şi o pune într-o altă zonă de memorie RAM. (cele 2 zone nu se intersectează)

;Pentru ca nu s-a dat dimensiunea matricii vom considera o matrice de 3 pe 3 care are coltul din stanga sus la adresa 501h:1h

mov ax, 501hmov ds, axmov [1h], 9

mov ax, 502hmov ds, axmov [1h], 8

mov ax, 503hmov ds, axmov [1h], 7

mov ax, 501hmov ds, axmov [2h], 6

mov ax, 502hmov ds, axmov [2h], 5

mov ax, 503hmov ds, axmov [2h], 4

mov ax, 501hmov ds, axmov [3h], 3

mov ax, 502hmov ds, axmov [3h], 2

mov ax, 503hmov ds, axmov [3h], 1

;vom copia aceasta matrice in zona de 505h:5h

mov cx, 3

linie:mov bx, cx

mov cx, 3coloana:

mov ax, 500hadd ax, cxmov ds, axmov dx, [bx]

add ax, 4mov ds, axmov [bx+4], dx

loop coloanamov cx, bx

loop linie

hlt

9