Sunteți pe pagina 1din 49

lab2.

asm Interschimbarea a dou locaii succesive sau aleatoare de

memorie
.model small .code start: mov ax,3000h mov ds,ax mov si,200h mov al,[si] inc si xchg al,[si] dec si mov [si],al mov ax,4c00h int 21h end start end

lab3.asm Adunarea a dou locaii succesive sau aleatoare de memorie .model small .code prog segment word public 'code' assume cs:prog, ds:date start: mov ax,3000h mov ds,ax mov si,200h mov ax,[si] add si,2 add ax,[si] jc afis_mesaj add si,2 mov [si],ax rev_DOS: mov ax,4c00h int 21 afis_mesaj: lea dx,mes_err mov ah,9 int 21h jmp rev_DOS prog ends .data

date segment mes_err db date ends end start end

'eroare:depasire dimensiune cuvant a rezultatului'

lab4a.asm a) Se adun n cuvinte ncepnd de la adresa 3000:200, cu rezultat

de lungime tot cuvnt (16 bii), fr detectarea depirii.


.model small .code prog segment word public 'code' assume cs:prog, ds:date start: mov ax,date mov ds,ax lea si,sir mov ax,0 mov cx,lung_sir reia_add: add ax,[si] add si,2 loop reia_add mov rezultat,ax rev_DOS: mov ax,4c00h int 21 afis_mesaj: mov ah,9 int 21 jmp rev_Dos prog ends .data date segment sir dw 0f54h,20000,0ff56h,8000 lung_sir equ ($-sir)/2 rezultat dw 2 dup(?) date ends end start

end lab6p1a.asm Inversarea octeilor (din curs)/ cuvintelor (la laborator) dintr-un

ir de valori, de tip cuvnt, respectiv de tip dublu cuvnt.


.model small .data mesaj dw 'Ex','em','pl','u ','pr','og','ra','m ','2$' lung_mesaj equ ($-mesaj)/2 linie_noua db 0dh,0ah,'$' .code start: mov ax, @data mov ds, ax lea dx, mesaj mov ah, 9 int 21h lea dx, linie_noua mov ah, 9 int 21h lea si, mesaj mov cx, lung_mesaj iar: mov ax, [si] xchg al, ah mov [si], ax add si, type mesaj loop iar lea dx, mesaj mov ah, 9 int 21h mov ax, 4c00h int 21h end start lab6p1b.asm .model small .data mesaj dd 30313233h,34353637h,38393130h;4578656dh,706c7520h,70726f67h,72616d20h,32622 024h lung_mesaj equ ($-mesaj)/2 linie_noua db 0dh,0ah,'$'

.code start: mov ax, @data mov ds, ax lea dx, mesaj mov ah, 9 int 21h lea dx, linie_noua mov ah, 9 int 21h lea si, mesaj mov cx, lung_mesaj iar: mov ax, [si] xchg ax, [si+2] mov [si], ax add si, type mesaj loop iar lea dx, mesaj mov ah, 9 int 21h mov ax, 4c00h int 21h end start lab6p2a.asm Diverse operaii (depuneri/ extrageri) cu stiva, utiliznd

instruciunile specifice (push/ pop), dar i referirea i citirea informaiilor din stiv utiliznd registrul BP ca registru de baz.S se scrie un program care citete caractere de la tastatur (funcia 1) le depune n stiv i apoi le extrage din stiv i le tiprete (funcia 2) pe o linie nou, n ordine invers. Citirea se va face pn la introducerea unui anumit caracter (prima varianta) sau se vor citi un anumit numr de caractere (a doua variant, utiliznd instruciunea loop).
.model small .data caracter db 2eh ;'.' sf_linie db 0dh,0ah,'$' .stack 100 .code start:

mov ax, @data mov ds, ax mov cx, 0 bucla: mov ah, 1h int 21h push ax inc cx cmp al, caracter jnz bucla lea dx, sf_linie mov ah, 9h int 21h bucla2: pop dx mov ah, 2 int 21h loop bucla2 mov ax, 4c00h int 21h end start lab6p2b.asm .model small .data nr_car dw 0ah ;10 sf_linie db 0dh,0ah,'$' .stack 100 .code start: mov ax, @data mov ds, ax mov cx, nr_car bucla: mov ah, 1h int 21h push ax loop bucla lea dx, sf_linie mov ah, 9h int 21h mov cx, nr_car bucla2: pop dx mov ah, 2 int 21h

loop bucla2 mov ax, 4c00h int 21h end start lab6p3.asm Afiarea codurilor ASCII ale tastelor (din curs), precum i a

codurilor de scanare, utiliznd funcia 0, a ntreruperii specifice tastaturii, int 16h, care returneaz n (AH, AL) codul de scanare i codul ASCII (sau 0, dac este o tast special-funcional, de deplasare, 'CTRL', 'insert', 'delete' etc.).
.model small .data tabela db '0123456789ABCDEF' string db 'Codul de scanare: Codul ASCII: $' .code start: mov ax, @data mov ds, ax mov ax, 0h int 16h mov cl, al and al, 0fh xlat [string] ;transfer din tabla de octeti mov string[33], al mov al, cl shr al, 4 xlat [string] mov string[32], al mov al, ah and al, 0fh xlat [string] mov string[18], al mov al, ah shr al, 4 xlat [string] mov string[17], al lea dx, string mov ah, 9h int 21h mov ax, 4c00h int 21h .stack 10

end start lab6p4.asm Exemple de iniializare a registrelor generale (BX, SI i DI) i a

celor segment, utiliznd instruciuni de transfer adrese.


.model small .data sir dw 20 dup (?) adr_sir dd sir adr_w dw 0123h, 4567h ptr_1 dd 76543210h .code start: mov ax, @data mov ds, ax lea bx, sir ;bx = offset sir lds si, adr_sir ;ds = segment sir, si = offset sir les di, dword ptr adr_w ;es = 4567h, di = 0123h lds si, ptr_1 ;ds = 7654h, si = 3210h mov ax, 4c00h int 21h end start lab6p5.asm Modificarea i afiarea indicatorilor de stare i control, utiliznd

instruciunile specifice.
.model small .data flags db 'x NT IQPL OF DF IF TF SF ZF x AF x PF x CF $' modif db 'Modificarea lui CF (not)$' zero db '0 $' unu db '1 $' sf_linie db 0dh,0ah,'$' .code start: mov ax, @data mov ds, ax pushf mov bp, sp mov bx, [bp] mov cx, 16 lea dx, flags mov ah, 9h int 21h lea dx, sf_linie

int 21h bucla: shl bx, 1 jc unu_ lea dx, zero int 21h jmp sf unu_: lea dx, unu int 21h sf: loop bucla popf lea dx, sf_linie int 21h lea dx, modif int 21h lea dx, sf_linie int 21h lahf xor ah, 01h sahf pushf mov bp, sp mov bx, [bp] mov cx, 16 lea dx, flags mov ah, 9h int 21h lea dx, sf_linie int 21h bucla2: shl bx, 1 jc unu_2 lea dx, zero int 21h jmp sf2 unu_2: lea dx, unu int 21h sf2: loop bucla2 sub sp, 2 mov ax, 4c00h int 21h .stack 10

;tiparim prima linie

;refacem indicatorii la astarea de la inceput

;modificam cf folosind lahf

;tipariam a doua linie

end start lab7p1.asm Programul de adunare a dou numere, fr semn, reprezentate pe

mai multe cuvinte (octei), la care rezultatul se va depune peste primul numr, va fi modificat pentru a realiza i adunarea/ scderea numerelor cu semn. Verificai condiia de depire a formatului de reprezentare pentru cele dou situaii: numere cu i fr semn.
.model small .data overflow db 'Depasire',0dh,0ah,'$' carry db 'Transport',0dh,0ah,'$' numar1 dw 0h,0h,0h,08000h lung equ ($-numar1)/2 numar2 dw 0h,0h,0h,08000h .code start: mov ax, @data mov ds, ax mov cx, lung mov si, 0 clc bucla: mov ax, numar1[si] adc ax, numar2[si] mov numar1[si], ax jno no_over mov bx, 1 no_over: inc si inc si loop bucla jnc fara_transport ;testam transportul si depasirea pt. ultima adunare lea dx, carry mov ah, 9h int 21h fara_transport: cmp bx, 1 jne fara_depasire lea dx, overflow mov ah, 9h int 21h fara_depasire: mov ax, 4c00h int 21h

end start lab7p2a.asm .model small .data overflow db 'Depasire',0dh,0ah,'$' carry db 'Transport',0dh,0ah,'$' numar1 dw 0h,0h,0h,0h,08000h lung1 equ ($-numar1)/2 numar2 dw 0ffffh,0ffffh,0ffffh,0ffffh,0ffffh,08fffh lung2 equ ($-numar2)/2 .code start: mov ax, @data mov ds, ax lea bx, numar1 mov di, lung1 lea bp, numar2 mov si, lung2 cmp di, si jge e_ok xchg bx, bp xchg di, si e_ok: ;bx si di contin numarul mai lung sub di, si mov cx, si mov si, 0 clc bucla1: ;facem tot ce trebuie sa adunam numerele :P mov ax, bx[si] adc ax, ds:bp[si] mov bx[si], ax mov dx, 0 jno no_over mov dx, 1 no_over: inc si inc si loop bucla1 mov cx, di lahf test word ptr ds:bp[si]-type numar1, 08000h mov di, 0h jz semnplus mov di, 0ffffh semnplus:

sahf bucla2: lahf cmp cx, 0 je gata sahf adc bx[si], di mov dx, 0 jno no_over2 mov dx, 1 no_over2: inc si inc si dec cx jmp bucla2 gata: sahf mov di, dx jnc fara_transport ;testam transportul si depasirea pt. ultima adunare lea dx, carry mov ah, 9h int 21h fara_transport: cmp di, 1 jne fara_depasire lea dx, overflow mov ah, 9h int 21h fara_depasire: mov ax, 4c00h int 21h end start lab7p2b.asm Acelai lucru trebuie realizat i pentru programul care adun 2

numere reprezentate pe mai multe cuvinte i depune rezultatul peste cel mai lung, adic modificai-l pentru numere cu semn. De asemenea, modificai-l pentru a nsuma numere zecimal mpachetate, respectiv nempachetate.
.model small .data carry db 'Transport',0dh,0ah,'$' numar1 db 9h,9h,9h,9h,0h lung1 equ ($-numar1) numar2 db 1h,1h,0h,0h,0h lung2 equ ($-numar2)

.code start: mov ax, @data mov ds, ax lea bx, numar1 mov di, lung1 lea bp, numar2 mov si, lung2 cmp di, si jge e_ok xchg bx, bp xchg di, si e_ok: sub di, si mov cx, si mov si, 0 clc bucla1: mov al, bx[si] adc al, ds:bp[si] aaa mov bx[si], al inc si loop bucla1 mov cx, di bucla2: lahf cmp cx, 0 je gata sahf mov al, 0 adc al, bx[si] aaa mov bx[si], al inc si dec cx jmp bucla2 gata: sahf jnc fara_transport lea dx, carry mov ah, 9h int 21h fara_transport: mov cx, si bucla3:

;bx si di contin numarul mai lung

;testam transportul si depasirea pt. ultima adunare

dec si mov dl, bx[si] add dl, 30h mov ah, 2h int 21h loop bucla3 mov ax, 4c00h int 21h end start lab7p2c.asm .model small .data carry db 'Transport',0dh,0ah,'$' numar1 db 99h,9h lung1 equ ($-numar1) numar2 db 1h,1h lung2 equ ($-numar2) .code start: mov ax, @data mov ds, ax lea bx, numar1 mov di, lung1 lea bp, numar2 mov si, lung2 cmp di, si jge e_ok xchg bx, bp xchg di, si e_ok: ;bx si di contin numarul mai lung sub di, si mov cx, si mov si, 0 clc bucla1: mov al, bx[si] adc al, ds:bp[si] daa mov bx[si], al inc si loop bucla1 mov cx, di bucla2: lahf cmp cx, 0

je gata sahf mov al, 0 adc al, bx[si] daa mov bx[si], al inc si dec cx jmp bucla2 gata: sahf jnc fara_transport lea dx, carry mov ah, 9h int 21h fara_transport: mov cx, si bucla3: dec si mov dl, bx[si] shr dl, 4 add dl, 30h mov ah, 2h int 21h mov dl, bx[si] and dl, 0fh add dl, 30h mov ah, 2h int 21h loop bucla3 mov ax, 4c00h int 21h end start

;testam transportul si depasirea pt. ultima adunare

lab7p3a.asm Definii complet i programele care determinau complementul

fa de 2 al unui numr reprezentat pe mai multe cuvinte (octei), n cele dou variante. Programele vor tipri un mesaj corespunztor pentru cele dou situaii extreme de calcul al complementului: pentru 0, la care complementul este acelai, i pentru valoarea minim negativ, pentru care nu se poate calcula complementul.
.model small

.data depasire db 'Depasire',0dh,0ah,'$' zero db 'Zero',0dh,0ah,'$' numar dw 0h,0h,0h,08000h lung equ ($-numar)/type numar .code start: mov ax, @data mov ds, ax mov cx, lung mov si, 0 mov bx, 0 mov dx, 0 stc bucla1: or bx, dx mov ax, numar[si] mov dx, ax not ax adc ax, 0 mov numar[si], ax inc si inc si loop bucla1 cmp bx, 0 jne sf cmp dx, 0 jne depas lea dx, zero mov ah, 9h int 21h jmp sf depas: cmp dx, 08000h jne sf lea dx, depasire mov ah, 9h int 21h sf: mov ax, 4c00h int 21h end start lab7p3b.asm .model small .data

depasire db 'Depasire',0dh,0ah,'$' zero db 'Zero',0dh,0ah,'$' numar db 0ffh,0ffh,0ffh,07fh lung equ ($-numar)/type numar .code start: mov ax, @data mov ds, ax mov cx, lung mov si, 0 mov bl, 0 mov dl, 0 stc bucla1: or bl, dl mov al, numar[si] mov dl, al not al adc al, 0 mov numar[si], al inc si loop bucla1 cmp bl, 0 jne sf cmp dl, 0 jne depas lea dx, zero mov ah, 9h int 21h jmp sf depas: cmp dl, 080h jne sf lea dx, depasire mov ah, 9h int 21h sf: mov ax, 4c00h int 21h end start lab7p4.asm Testai exemplele prezentate la curs pentru operaiile de nmulire/

mprire.
.model small .code

start: mov al, 7 mov cl, 7 mul cl aam mov ah, 8 mov al, 9 aad mov bl, 4 div bl mov dh, ah aam mov ax, 4c00h int 21h end start lab7p5a.asm Modificai programul pentru afiarea n zecimal a valorii din AX

fr semn, pentru a o afia cu semn, i apoi extindei programul pentru a afia valoarea fr zerourile nesemnificative.
.model small .data numar dw 0800h .code start: mov ax, @data mov ds, ax mov ax, [numar] cmp ax, 0 mov bx, ax jns pozitiv mov dl, '-' mov ah, 2h int 21h neg bx pozitiv: mov ax, bx mov cx, 100 mov dx, 0 div cx push dx mov dx, 0 div cx

push dx mov dx, ax cmp dl, 0 jz e0_1 add dl, 30h mov ah, 2h int 21h pop ax aam mov dx, ax jmp nue0_1 e0_1: pop ax aam mov dx, ax cmp dh, 0 jz e0_2 nue0_1: xchg dh, dl add dl, 30h mov ah, 2h int 21h xchg dh, dl jmp nue0_2 e0_2: cmp dl, 0 jz e0_3 nue0_2: add dl, 30h mov ah, 2h int 21h pop ax aam mov dx, ax jmp nue0_3 e0_3: pop ax aam mov dx, ax cmp dh, 0 jz e0_4 nue0_3: xchg dh, dl add dl, 30h mov ah, 2h int 21h

xchg dh, dl e0_4: add dl, 30h mov ah, 2h int 21h mov ax, 4c00h int 21h .stack 10 end start lab7p5b.asm .model small .data numar dw 0ffffh .code start: mov ax, @data mov ds, ax mov ax, [numar] mov cx, 100 mov dx, 0 div cx push dx mov dx, 0 div cx push dx mov dx, ax cmp dl, 0 jz e0_1 add dl, 30h mov ah, 2h int 21h pop ax aam mov dx, ax jmp nue0_1 e0_1: pop ax aam mov dx, ax cmp dh, 0 jz e0_2 nue0_1: xchg dh, dl add dl, 30h mov ah, 2h

int 21h xchg dh, dl jmp nue0_2 e0_2: cmp dl, 0 jz e0_3 nue0_2: add dl, 30h mov ah, 2h int 21h pop ax aam mov dx, ax jmp nue0_3 e0_3: pop ax aam mov dx, ax cmp dh, 0 jz e0_4 nue0_3: xchg dh, dl add dl, 30h mov ah, 2h int 21h xchg dh, dl e0_4: add dl, 30h mov ah, 2h int 21h mov ax, 4c00h int 21h .stack 10 end start lab7p6a.asm mprirea unui numr de 32 de bii la unul de 16 bii (fr semn,

i apoi cu semn).
.model small .data numar dd 0ffff0001h impart dw 0ffh .code start: mov ax, @data mov ds, ax mov dx, 0h

mov ax, word ptr [numar+2] mov cx, [impart] div cx mov word ptr [numar+2], ax mov ax, word ptr [numar] div cx mov word ptr [numar], ax ;numar contine catul, dx contine restul mov ax, 4c00h int 21h end start lab7p6b.asm .model small .data numar dd 0ffff0001h impart dw 0ffh .code start: mov ax, @data mov ds, ax mov ax, word ptr [numar+2] cwd mov cx, [impart] idiv cx mov word ptr [numar+2], ax mov ax, word ptr [numar] idiv cx mov word ptr [numar], ax ;numar contine catul, dx contine restul cmp word ptr[numar+2], 0 jne sf cwd mov word ptr[numar+2], dx sf: mov ax, 4c00h int 21h end start lab8p1.asm Determinarea numrului de bii 0 dintr-o variabil. .386 .model small .data lung equ 8 variabila dw lung dup(0abcdh) numar0 db ? .code

start: mov ax, @data mov ds, ax mov cx, lung mov si, 0 mov bl, 0 bucla1: mov dx, variabila[si] not dx bucla2: bsf di, dx jz afara btr dx, di inc bl jmp bucla2 afara: add si, 2 loop bucla1 mov numar0, bl mov ax, 4c00h int 21h end start lab8p2.asm Afiarea n octal a coninutului perechii de registre DX:AX. .model small .stack 20h .data variabila dd 0f1234567h .code tip_octal proc push ax push bx push cx push dx push si mov bx, dx mov si, ax shr dx, 14 add dl, 30h mov ah, 2h int 21h shl si, 1 rcl bx, 1 rol bx, 1 mov cx, 5

prim: rol bx, 3 mov dl, bl and dl, 07h add dl, 30h int 21h loop prim mov cx, 5 mov bx, si doi: rol bx, 3 mov dl, bl and dl, 07h add dl, 30h int 21h loop doi pop si pop dx pop cx pop bx pop ax ret tip_octal endp start: mov ax, @data mov ds, ax mov ax, word ptr [variabila] mov dx, word ptr [variabila+2] call tip_octal mov ax, 4c00h int 21h end start lab8p3.asm Afiarea n binar a coninutului registrului BX. .model small .data continut dw 0f834h .code start: mov ax, @data mov ds, ax mov bx, [continut] mov cx, 16 mov ah, 2h bucla:

shl bx, 1 mov dl, '0' jnc ezero mov dl, '1' ezero: int 21h loop bucla mov ax, 4c00h int 21h end start lab8p4.asm Determinarea numrului de perechi de valori egale din dou

iruri.
.model small .data sir1 dw 04235h,0fab3h,03ad3h,05434h lung1 equ ($-sir1)/type sir1 sir2 dw 04235h,03754h,03ad3h lung2 equ ($-sir2)/type sir2 .code assume ds:_data, es:_data start: mov cx, lung1 cmp cx, lung2 jle ok mov cx, lung2 ok: mov ax, @data mov ds, ax mov es, ax lea si, sir1 lea di, sir2 mov ax, 0 bucla: cmps sir1, sir2 jnz diferite inc ax diferite: loop bucla mov ax, 4c00h int 21h end start

lab8p5.asm Determinarea primei i ultimei apariii a unei anumite valori ntr-

un ir. Este vorba de indexul din ir, care eventual poate fi tiprit n octal utiliznd programul 2. Dac nu este gsit de loc se va tipri un mesaj corespunztor.
.model small .stack 100h .data mesaj db 'Valoarea nu exista$' sf_linie db 0dh,0ah,'$' sir dw 04235h,0fab3h,03ad3h,05434h,04235h,03754h,03ad3h lung equ ($-sir)/type sir valoare dw 04235h .code tip_octal proc push ax push bx push cx push dx shl ax, 1 mov bx, ax rcl dx, 1 and dl, 01h add dl, 30h mov ah, 2h int 21h mov cx, 5 bucla: rol bx, 3 mov dl, bl and dl, 07h add dl, 30h int 21h loop bucla pop dx pop cx pop bx pop ax ret tip_octal endp start: mov ax, @data mov ds, ax mov es, ax

mov ax, valoare mov cx, lung lea di, sir mov si, di cld repnz scasw cmp cx, 0 jz nuexista sub di, si shr di, 1 dec di mov ax, di call tip_octal mov ah, 9h lea dx, sf_linie int 21h mov ax, valoare mov cx, lung lea di, sir[(lung-1)*type sir] lea si, sir std repnz scasw add di, type sir sub di, si shr di, 1 mov ax, di call tip_octal mov ax, 4c00h int 21h nuexista: lea dx, mesaj mov ah, 9h int 21h mov ax, 4c00h int 21h end start lab8p6.asm Determinarea existenei i a poziiei (indexul) unui subir de

caractere ntr-un ir.


.model small .data sir db 'alabalaportocala$' lung_sir equ ($-sir)/type sir-1 subsir db 'oc$' lung_sub equ ($-subsir)/type sir-1 sf_linie db 0dh,0ah,'$'

mesaj db 'nu exista$' .stack 100h .code tip_octal proc push ax push bx push cx push dx shl ax, 1 mov bx, ax rcl dx, 1 and dl, 01h add dl, 30h mov ah, 2h int 21h mov cx, 5 bucla: rol bx, 3 mov dl, bl and dl, 07h add dl, 30h int 21h loop bucla pop dx pop cx pop bx pop ax ret tip_octal endp assume ds:_data, es:_data start: mov ax, @data mov ds, ax mov es, ax lea dx, sir mov ah, 9h int 21h lea dx, sf_linie int 21h lea dx, subsir int 21h lea dx, sf_linie int 21h mov cx, lung_sir-lung_sub+1 bucla2: mov al, [subsir]

mov bx, cx lea bx, sir[bx] mov di, lung_sir-lung_sub+1 sub di, bx repnz scasb push cx dec di lea si, subsir mov cx, lung_sub repz cmps sir, subsir jnz notfound cmp cx, 0 jnz notfound pop cx inc cx mov ax, lung_sir-lung_sub+1 sub ax, cx call tip_octal mov ax, 4c00h int 21h notfound: pop cx inc cx loop bucla2 lea dx, mesaj mov ah, 9h int 21h mov ax, 4c00h int 21h end start lab8p7a.asm Inserarea / eliminarea unui anumit element, specificat fie prin

poziie fie prin valoare, dintr-un ir.


.model small .data sf_linie db 0dh, 0ah, '$' sir db 'alablaportocala$',10 dup(?) lung dw 16 element db 'a' ;insereaza element pe pozitie pozitie dw 10 .code start: mov ax, @data mov ds, ax mov es, ax

lea dx, sir mov ah, 9h int 21h lea dx, sf_linie int 21h mov cx, lung sub cx, pozitie inc cx mov bx, lung lea si, sir[bx] inc bx lea di, sir[bx] std rep movsb mov al, element stosb lea dx, sir int 21h mov ax, 4c00h int 21h end start lab8p7b.asm .model small .data sf_linie db 0dh, 0ah, '$' sir db 'alabalaportocala$',10 dup(?) lung dw 17 ;elimina element de pe pozitie pozitie dw 10 .code start: mov ax, @data mov ds, ax mov es, ax lea dx, sir mov ah, 9h int 21h lea dx, sf_linie int 21h mov cx, lung sub cx, pozitie inc cx mov bx, pozitie lea di, sir[bx] inc bx lea si, sir[bx]

cld rep movsb lea dx, sir int 21h mov ax, 4c00h int 21h end start lab8p7c.asm .model small .data sir1 db 'alabala', 10 dup(?) lung1 dw 7 sir2 db 'portocala', 10 dup(?) lung2 dw 9 sf_linie db 0dh,0ah,'$' .code assume ds:_data, es:_data start: mov ax, @data mov ds, ax mov es, ax lea bx, sir1 add bx, lung1 mov byte ptr [bx], '$' sub bx, lung1 mov dx, bx mov ah, 9h int 21h lea dx, sf_linie int 21h lea bx, sir2 add bx, lung2 mov byte ptr [bx], '$' sub bx, lung2 mov dx, bx int 21h lea dx, sf_linie int 21h mov cx, lung2 lea di, sir1 add di, lung1 lea si, sir2 rep movs sir1, sir2 mov al, '$' stos sir1

lea dx, sir1 int 21h mov ax, 4c00h int 21h end start lab8p8.asm Concatenarea a dou iruri de caractere, cu afiarea lor nainte de

concatenare i dup aceasta.


.model small .data sir1 db 'alabala', 10 dup(?) lung1 dw 7 sir2 db 'portocala', 10 dup(?) lung2 dw 9 sf_linie db 0dh,0ah,'$' .code assume ds:_data, es:_data start: mov ax, @data mov ds, ax mov es, ax lea bx, sir1 add bx, lung1 mov byte ptr [bx], '$' sub bx, lung1 mov dx, bx mov ah, 9h int 21h lea dx, sf_linie int 21h lea bx, sir2 add bx, lung2 mov byte ptr [bx], '$' sub bx, lung2 mov dx, bx int 21h lea dx, sf_linie int 21h mov cx, lung2 lea di, sir1 add di, lung1 lea si, sir2 rep movs sir1, sir2 mov al, '$'

stos sir1 lea dx, sir1 int 21h mov ax, 4c00h int 21h end start lab8p9.asm Rescriei programul de test pentru memorie, ce utilizeaz

algoritmul lui March, astfel nct s preia configuraiile de test (AAh, 55h, FFh, 01h, 00h) dintr-o zon de memorie (fr a utiliza artificiul cu registrul DX, din curs), n aceast ordine, i comparai timpii de execuie (ai acestui program cu cel din curs). Pentru a determina timpul de execuie utilizai funcia DOS, 2Ch (citire or sistem).
seg_test segment zona db 65535 dup(?) seg_test ends seg_stiva segment stack ceva dw 10h dup (?) seg_stiva ends seg_cod segment assume cs:seg_cod pattern db 0aah,55h,0ffh,01h,00h,00h lung equ ($-pattern) mesaj db 'Ooops, ai pus-o$' testeaza proc ;ds = es = seg testat, cx = lungimea push ax push bx push cx mov bx, 0 mov al, pattern[bx] mov di, 0 cld rep stosb inceput: mov ah, al inc bx mov al, pattern[bx] pop cx push cx cld inc di test bx, 01h jp invers std dec di

dec di invers: mov si, di bucla: lodsb xor al, ah jnz eroare mov al, pattern[bx] stosb loop bucla cmp bl, lung jl inceput pop cx pop bx pop ax ret eroare: stc dec si pop cx pop bx pop ax ret testeaza endp start: mov ax, seg_test mov ds, ax mov es, ax mov cx, 65535 clc call testeaza jnc gata mov ax, cs mov ds, ax lea dx, mesaj mov ah, 9h int 21h gata: mov ax, 4c00h int 21h seg_cod ends end start

lab9p1.asm Modificai programul ce execut diferite secvene de program, n

funcie de opiunea utilizatorului, introdus de la tastatur, pentru a executa secvene aflate n alte segmente (adic salturi de tip far).

seg_data segment executie db 0Dh, 0Ah, 'Executa secventa (1,2,3 sau 4=stop):$' mes_secv1 db 'S-a executat secventa 1', 0dh, 0ah, '$' mes_secv2 db 'S-a executat secventa 2', 0dh, 0ah, '$' mes_secv3 db 'S-a executat secventa 3', 0dh, 0ah, '$' tab_secv label word dd far ptr secv1 dd far ptr secv2 dd far ptr secv3 dd far ptr gata seg_data ends alt_seg segment secv1: lea dx, mes_secv1 mov ah, 9 int 21h jmp far ptr iar alt_seg ends seg_code segment assume cs:seg_code, ds:seg_data start: mov ax, seg_data mov ds, ax iar: lea dx, executie mov ah, 9 int 21h mov ah, 1 int 21h sub al, 31h jc iar cmp al, 4 jnc iar cbw mov bx, ax shl bx, 2 jmp dword ptr tab_secv[bx] secv2: lea dx, mes_secv2

mov ah, 9 int 21h jmp short iar secv3: lea dx, mes_secv3 mov ah, 9 int 21h jmp short iar gata: mov ax, 4c00h int 21h seg_code ends seg_stack segment stack dw 20h dup(?) seg_stack ends end start lab9p2a.asm Scriei programul pentru ordonarea unui ir de valori (de tip octet

sau cuvnt), utiliznd diferite metode: metoda bulelor (inversiunilor), selecie direct, inserare direct, etc.
.model small .data sir db 023h, 034h, 0ffh, 000h, 001h, 0abh, 034h lung equ ($-sir)/type sir .code assume es:_data start: mov ax, @data mov ds, ax mov es, ax buclamare: mov cx, lung dec cx lea si, sir lea di, sir[type sir] cld mov bl, 0 buclamica: cmps sir, sir jbe suntok mov al, si[-(type sir)] xchg al, di[-(type sir)] mov si[-(type sir)], al mov bl, 1

;pt cuvant se modifica db in dw si ;registrul al in ax

suntok: loop buclamica test bl, 0ffh jnz buclamare mov ax, 4c00h int 21h end start lab9p2b.asm .model small .data sir db 023h, 034h, 0ffh, 002h, 001h, 0abh, 034h lung equ ($-sir)/type sir .code assume es:_data start: mov ax, @data mov ds, ax mov es, ax lea dx, sir mov bp, lung-1 inceput: mov si, dx mov bl, [si] mov di, si mov cx, bp add si, type sir bucla: lods sir cmp al, bl jae nuemaimare mov bl, al mov di, si sub di, type sir nuemaimare: loop bucla mov si, dx movs sir, sir mov [si-(type sir)], bl add dx, type sir dec bp test bp, 0ffffh jnz inceput mov ax, 4c00h int 21h end start

;pt cuvant se modifica db in dw si ;registrul al in ax, bl in bx

lab9p2c.asm .model small .data sir dw 023h, 034h, 0ffh, 002h, 0cbh, 0abh, 034h lung equ ($-sir)/type sir .code assume es:_data start: mov ax, @data mov ds, ax mov es, ax mov dx, 1 lea si, sir[type sir] inceput: lea di, sir mov ax, [si] mov cx, dx bucla: scas sir jbe gasit loop bucla gasit: jcxz peste mov bx, si mov di, si sub si, type sir std rep movs sir, sir stos sir cld mov si, bx peste: add si, type sir inc dx cmp dx, lung jnz inceput mov ax, 4c00h int 21h end start

;pt octet se modifica dw in dl si ;registrul ax in al

lab9p3a.asm Definii proceduri i programele ce le apeleaz, pentru inserarea/

eliminarea unui subir dintr-un ir dat (transferul parametrilor la proceduri se face prin registre).

.model small .data sir db 'alabalaportocala$', 50 dup(?) lung_sir equ ($-sir)-50 subsir db 'lamaia' lung_subsir equ ($-subsir) sf_linie db 0dh,0ah,'$' .code insereaza proc ;di adresa destinatiei, si adresa sursei add di, dx ;ax pozitia in destinatie push cx ;dx lungimea dest, cx lungimea sursei push si dec di mov si, di add di, cx mov cx, dx sub cx, ax std rep movsb pop si pop cx cld inc di sub di, cx rep movsb ret insereaza endp start: mov ax, @data mov ds, ax mov es, ax mov ah, 9h lea dx, sir int 21h lea dx, sf_linie int 21h lea di, sir lea si, subsir mov ax, 7 mov dx, lung_sir mov cx, lung_subsir call insereaza lea dx, sir mov ah, 9h int 21h mov ax, 4c00h

int 21h .stack 100h end start lab9p3b.asm .model small .data sir db 'alabalaportocala$' lung_sir equ ($-sir) sf_linie db 0dh,0ah,'$' .code elimina proc add di, ax push si mov si, di add si, dx sub cx, ax cld rep movsb pop si ret elimina endp start: mov ax, @data mov ds, ax mov es, ax mov ah, 9h lea dx, sir int 21h lea dx, sf_linie int 21h lea di, sir mov ax, 3 mov dx, 4 mov cx, lung_sir call elimina lea dx, sir mov ah, 9h int 21h mov ax, 4c00h int 21h .stack 100h end start

;di adresa destinatiei ;ax pozitia in destinatie ;cx lungimea dest, dx lungimea subsirului

lab9p4.asm Scriei un program pentru construirea unui ir, format din

caractere introduse de la tastatur, ntr-o zon de memorie, i care apoi s fie tiprit direct i invers, pe cte o linie nou.
.model small .data sir db 100 dup(?) lungmax equ ($-sir) sf_linie db 0dh,0ah,'$' .code tipareste proc push ax push dx mov ah, 2h bucla2: lodsb mov dl, al int 21h loop bucla2 pop dx pop ax ret tipareste endp start: mov ax, @data mov ds, ax mov es, ax lea di, sir mov cx, lungmax cld mov ah, 1h bucla: int 21h cmp al, 0dh jz afara stosb loop bucla afara: mov ah, 9h lea dx, sf_linie int 21h cld lea si, sir mov bx, lungmax sub bx, cx

;si inceputul sirului, cx lungimea sirului

mov cx, bx call tipareste int 21h std lea si, sir add si, bx dec si mov cx, bx call tipareste mov ax, 4c00h int 21h end start .stack 100h lab9p5.asm Scriei programul care citete 2 iruri de caractere, le depune n

memorie n format ASCIIZ, i apoi le concateneaz utiliznd o procedur, care primete prin registre adresele celor dou iruri surs, i a irului destinaie (se presupune c sunt n acelai segment). Se va afia irul astfel obinut.
.model small .data lung1 equ 100 sir1 db lung1 dup(?) lung2 equ 100 sir2 db lung2 dup(?) sirfinal db lung1+lung2 dup(?) sf_linie db 0dh,0ah,'$' .code citeste proc push ax cld mov ah, 1h bucla: int 21h cmp al, 0dh jz afara stosb loop bucla afara: mov al, 00h stosb pop ax

;di destinatia, cx lungimea maxima

ret citeste endp concat proc cld bucla1: movsb test byte ptr [si], 0ffh jz afara1 jmp bucla1 afara1: mov si, dx bucla2: movsb test byte ptr [si], 0ffh jz afara2 jmp bucla2 afara2: ret concat endp start: mov ax, @data mov ds, ax mov es, ax lea di, sir1 mov cx, lung1 call citeste lea dx, sf_linie mov ah, 9h int 21h lea di, sir2 mov cx, lung2 call citeste int 21h lea di, sirfinal lea si, sir1 lea dx, sir2 call concat lea si, sirfinal mov ah, 2h cld bucla3: lodsb mov dl, al test al, 0ffh jz afara3 int 21h

;di sirul final, si sirul1, dx sirul2

jmp bucla3 afara3: mov ax, 4c00h int 21h end start .stack 100h lab9p6a.asm Scriei programul pentru citirea a 2 numere (ce vor fi depuse n

memorie n format zecimal mpachetat, sau nempachetat), se vor aduna i se va afia rezultatul.
.model small .data lungmax equ 100 numar1 db lungmax dup(0) numar2 db lungmax dup(0) sf_linie db 0dh, 0ah, '$' .code citeste proc push ax push bx mov bx, cx mov ah, 1h bucla: int 21h sub al, 30h jl afara cmp al, 9 jg afara push ax loop bucla afara: sub bx, cx mov cx, bx jcxz nimic cld buclaciunspe: pop ax stosb loop buclaciunspe mov cx, bx nimic: pop bx pop ax ret

;di destinatia, cx lungimea maxima ;intoarce cx lungimea citita

citeste endp aduna proc push ax cmp dx, cx jge e_ok xchg di, si xchg dx, cx e_ok: jcxz zero2 push di push dx sub dx, cx clc bucla1: lodsb adc al, [di] aaa stosb loop bucla1 mov cx, dx bucla2: jcxz gata mov al, 0 adc al, [di] aaa stosb loop bucla2 gata: pop dx jnc fara_transport inc dx mov byte ptr [di], 1 fara_transport: pop di zero2: pop ax ret aduna endp afiseaza proc push ax push dx jcxz zero std add si, cx dec si mov ah, 2h

;di, si adresele de inceput ale sirurilor ;dx, cx lungimile numerelor ;intoarce di inceputul rez, dx lungimea lui ;di si dx contin numarul mai lung

;testam transportul si depasirea pt. ultima adunare

bucla3: lodsb mov dl, al add dl, 30h int 21h loop bucla3 zero: pop dx pop ax ret afiseaza endp start: mov ax, @data mov ds, ax mov es, ax lea di, numar1 mov cx, lungmax call citeste mov bx, cx lea dx, sf_linie mov ah, 9h int 21h lea di, numar2 mov cx, lungmax call citeste int 21h lea di, numar1 lea si, numar2 mov dx, bx call aduna mov si, di mov cx, dx call afiseaza mov ax, 4c00h int 21h end start .stack 100h lab9p6b.asm .model small .data lungmax equ 100 numar1 db lungmax dup(0) numar2 db lungmax dup(0) sf_linie db 0dh, 0ah, '$' .code

;si contine numarul, cx contine lungimea

citeste proc push ax push bx push dx shl cx, 1 mov bx, cx mov ah, 1h bucla: int 21h sub al, 30h jl afara cmp al, 9 jg afara push ax loop bucla afara: sub bx, cx mov cx, bx cld buclaciunspe: pop dx mov al, dl dec cx jcxz cxezero pop dx shl dl, 4 or al, dl cxezero: stosb jcxz afaradinbucla loop buclaciunspe afaradinbucla: mov cx, bx test bx, 01h jz nimic inc cx nimic: shr cx, 1 pop dx pop bx pop ax ret citeste endp aduna proc push ax cmp dx, cx

;di destinatia, cx lungimea maxima ;intoarce cx lungimea citita

;di, si adresele de inceput ale sirurilor ;dx, cx lungimile numerelor

jge e_ok xchg di, si xchg dx, cx e_ok: jcxz zero2 push di push dx sub dx, cx clc bucla1: lodsb adc al, [di] daa stosb loop bucla1 mov cx, dx bucla2: jcxz gata mov al, 0 adc al, [di] daa stosb loop bucla2 gata: pop dx jnc fara_transport inc dx mov byte ptr [di], 1 fara_transport: pop di zero2: pop ax ret aduna endp afiseaza proc push ax push dx jcxz zero std add si, cx dec si mov ah, 2h lodsb dec cx mov dl, al mov dh, dl

;intoarce di inceputul rez, dx lungimea lui ;di si dx contin numarul mai lung

;testam transportul si depasirea pt. ultima adunare

shr dl, 4 test dl, 0ffh jz cealalta add dl, 30h int 21h cealalta: mov dl, dh and dl, 0fh add dl, 30h int 21h bucla3: lodsb mov dl, al mov dh, dl shr dl, 4 add dl, 30h int 21h mov dl, dh and dl, 0fh add dl, 30h int 21h loop bucla3 zero: pop dx pop ax ret afiseaza endp start: mov ax, @data mov ds, ax mov es, ax lea di, numar1 mov cx, lungmax call citeste mov bx, cx lea dx, sf_linie mov ah, 9h int 21h lea di, numar2 mov cx, lungmax call citeste int 21h lea di, numar1 lea si, numar2 mov dx, bx call aduna

;si contine numarul, cx contine lungimea

mov si, di mov cx, dx call afiseaza mov ax, 4c00h int 21h end start .stack 100h

S-ar putea să vă placă și