IOCLA

60
lab2.asm Interschimbarea a două locaţii 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ă locaţii 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:

description

a

Transcript of IOCLA

Page 1: IOCLA

lab2.asm Interschimbarea a două locaţii succesive sau aleatoare de memorie

.model small

.codestart: mov ax,3000h mov ds,ax

mov si,200hmov al,[si]inc sixchg al,[si]dec simov [si],almov ax,4c00hint 21h

end startend

lab3.asm Adunarea a două locaţii succesive sau aleatoare de memorie

.model small

.codeprog segment word public 'code'

assume cs:prog, ds:datestart: mov ax,3000h

mov ds,axmov si,200hmov ax,[si]add si,2add ax,[si]jc afis_mesajadd si,2mov [si],ax

rev_DOS:mov ax,4c00hint 21

afis_mesaj:lea dx,mes_errmov ah,9int 21hjmp rev_DOS

prog ends.data

Page 2: IOCLA

date segmentmes_err db 'eroare:depasire dimensiune cuvant a rezultatului'date endsend start

end

lab4a.asm a) Se adună n cuvinte începând de la adresa 3000:200, cu rezultat de lungime tot cuvânt (16 biţi), fără detectarea depăşirii.

.model small

.codeprog segment word public 'code' assume cs:prog, ds:date

start: mov ax,datemov ds,axlea si,sirmov ax,0mov cx,lung_sir

reia_add:add ax,[si]add si,2loop reia_addmov rezultat,ax

rev_DOS:mov ax,4c00hint 21

afis_mesaj:mov ah,9int 21jmp rev_Dos

prog ends

.datadate segmentsir dw 0f54h,20000,0ff56h,8000lung_sir equ ($-sir)/2rezultat dw 2 dup(?)date endsend start

Page 3: IOCLA

end

lab6p1a.asm Inversarea octeţilor (din curs)/ cuvintelor (la laborator) dintr-un şir de valori, de tip cuvânt, respectiv de tip dublu cuvânt.

.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 21hend start

lab6p1b.asm.model small.data mesaj dd 30313233h,34353637h,38393130h;4578656dh,706c7520h,70726f67h,72616d20h,32622024h lung_mesaj equ ($-mesaj)/2 linie_noua db 0dh,0ah,'$'

Page 4: IOCLA

.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 21hend start

lab6p2a.asm Diverse operaţii (depuneri/ extrageri) cu stiva, utilizând

instrucţiunile specifice (push/ pop), dar şi referirea şi citirea informaţiilor din

stivă utilizând registrul BP ca registru de bază.Să se scrie un program care

citeşte caractere de la tastatură (funcţia 1) le depune în stivă şi apoi le

extrage din stivă şi le tipăreşte (funcţia 2) pe o linie nouă, în ordine inversă.

Citirea se va face până la introducerea unui anumit caracter (prima varianta)

sau se vor citi un anumit număr de caractere (a doua variantă, utilizând

instrucţiunea loop).

.model small

.data caracter db 2eh ;'.' sf_linie db 0dh,0ah,'$'.stack 100.code start:

Page 5: IOCLA

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 21hend 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

Page 6: IOCLA

loop bucla2 mov ax, 4c00h int 21hend start

lab6p3.asm Afişarea codurilor ASCII ale tastelor (din curs), precum şi a

codurilor de scanare, utilizând funcţia 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ă-funcţională, 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

Page 7: IOCLA

end start

lab6p4.asm Exemple de iniţializare a registrelor generale (BX, SI şi DI) şi a

celor segment, utilizând instrucţiuni 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 21hend start

lab6p5.asm Modificarea şi afişarea indicatorilor de stare şi control, utilizând

instrucţiunile 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

Page 8: IOCLA

int 21h bucla: ;tiparim prima linie shl bx, 1 jc unu_ lea dx, zero int 21h jmp sf unu_: lea dx, unu int 21h sf: loop bucla popf ;refacem indicatorii la astarea de la inceput lea dx, sf_linie int 21h lea dx, modif int 21h lea dx, sf_linie int 21h lahf ;modificam cf folosind 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: ;tipariam a doua linie 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

Page 9: IOCLA

end startlab7p1.asm Programul de adunare a două numere, fără semn, reprezentate pe

mai multe cuvinte (octeţi), la care rezultatul se va depune peste primul

număr, va fi modificat pentru a realiza şi adunarea/ scăderea numerelor cu

semn. Verificaţi condiţia de depăşire a formatului de reprezentare pentru

cele două situaţii: numere cu şi fără 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

Page 10: IOCLA

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:

Page 11: IOCLA

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 21hend startlab7p2b.asm Acelaşi lucru trebuie realizat şi pentru programul care adună 2

numere reprezentate pe mai multe cuvinte şi depune rezultatul peste cel mai

lung, adică modificaţi-l pentru numere cu semn. De asemenea, modificaţi-l

pentru a însuma numere zecimal împachetate, respectiv neîmpachetate.

.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)

Page 12: IOCLA

.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] 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 ;testam transportul si depasirea pt. ultima adunare lea dx, carry mov ah, 9h int 21h fara_transport: mov cx, si bucla3:

Page 13: IOCLA

dec si mov dl, bx[si] add dl, 30h mov ah, 2h int 21h loop bucla3 mov ax, 4c00h int 21hend 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

Page 14: IOCLA

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 ;testam transportul si depasirea pt. ultima adunare 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 21hend start

lab7p3a.asm Definiţi complet şi programele care determinau complementul

faţă de 2 al unui număr reprezentat pe mai multe cuvinte (octeţi), în cele

două variante. Programele vor tipări un mesaj corespunzător pentru cele

două situaţii extreme de calcul al complementului: pentru 0, la care

complementul este acelaşi, şi pentru valoarea minimă negativă, pentru care

nu se poate calcula complementul.

.model small

Page 15: IOCLA

.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 21hend start

lab7p3b.asm.model small.data

Page 16: IOCLA

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 21hend start

lab7p4.asm Testaţi exemplele prezentate la curs pentru operaţiile de înmulţire/

împărţire.

.model small

.code

Page 17: IOCLA

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 21hend start

lab7p5a.asm Modificaţi programul pentru afişarea în zecimal a valorii din AX

fără semn, pentru a o afişa cu semn, şi apoi extindeţi programul pentru a

afişa valoarea fără 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

Page 18: IOCLA

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

Page 19: IOCLA

xchg dh, dl e0_4: add dl, 30h mov ah, 2h int 21h mov ax, 4c00h int 21h.stack 10end 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

Page 20: IOCLA

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 10end start

lab7p6a.asm Împărţirea unui număr de 32 de biţi la unul de 16 biţi (fără 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

Page 21: IOCLA

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 21hend 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 21hend start

lab8p1.asm Determinarea numărului de biţi 0 dintr-o variabilă.

.386

.model small

.data lung equ 8 variabila dw lung dup(0abcdh) numar0 db ?.code

Page 22: IOCLA

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 21hend start

lab8p2.asm Afişarea în octal a conţinutului 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

Page 23: IOCLA

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 21hend start

lab8p3.asm Afişarea în binar a conţinutului 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:

Page 24: IOCLA

shl bx, 1 mov dl, '0' jnc ezero mov dl, '1' ezero: int 21h loop bucla mov ax, 4c00h int 21hend start

lab8p4.asm Determinarea numărului 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 21hend start

Page 25: IOCLA

lab8p5.asm Determinarea primei şi ultimei apariţii a unei anumite valori într-

un şir. Este vorba de indexul din şir, care eventual poate fi tipărit în octal

utilizând programul 2. Dacă nu este găsită de loc se va tipări un mesaj

corespunzător.

.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

Page 26: IOCLA

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 21hend start lab8p6.asm Determinarea existenţei şi a poziţiei (indexul) unui subşir 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,'$'

Page 27: IOCLA

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]

Page 28: IOCLA

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 21hend start

lab8p7a.asm Inserarea / eliminarea unui anumit element, specificat fie prin

poziţie 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

Page 29: IOCLA

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 21hend 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]

Page 30: IOCLA

cld rep movsb lea dx, sir int 21h mov ax, 4c00h int 21hend 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

Page 31: IOCLA

lea dx, sir1 int 21h mov ax, 4c00h int 21hend start

lab8p8.asm Concatenarea a două şiruri de caractere, cu afişarea 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, '$'

Page 32: IOCLA

stos sir1 lea dx, sir1 int 21h mov ax, 4c00h int 21hend start

lab8p9.asm Rescrieţi programul de test pentru memorie, ce utilizează algoritmul lui March, astfel încât să preia configuraţiile de test (AAh, 55h, FFh, 01h, 00h) dintr-o zonă de memorie (fără a utiliza artificiul cu registrul DX, din curs), în această ordine, şi comparaţi timpii de execuţie (ai acestui program cu cel din curs). Pentru a determina timpul de execuţie utilizaţi funcţia DOS, 2Ch (citire oră sistem).seg_test segment zona db 65535 dup(?)seg_test endsseg_stiva segment stack ceva dw 10h dup (?)seg_stiva endsseg_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

Page 33: IOCLA

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 21hseg_cod endsend start

Page 34: IOCLA

lab9p1.asm Modificaţi programul ce execută diferite secvenţe de program, în

funcţie de opţiunea utilizatorului, introdusă de la tastatură, pentru a executa

secvenţe 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 gataseg_data endsalt_seg segment secv1: lea dx, mes_secv1 mov ah, 9 int 21h jmp far ptr iaralt_seg endsseg_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

Page 35: IOCLA

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 21hseg_code endsseg_stack segment stack dw 20h dup(?)seg_stack endsend start

lab9p2a.asm Scrieţi programul pentru ordonarea unui şir de valori (de tip octet

sau cuvânt), utilizând diferite metode: metoda bulelor (inversiunilor),

selecţie directă, inserare directă, etc.

.model small

.data sir db 023h, 034h, 0ffh, 000h, 001h, 0abh, 034h ;pt cuvant se modifica db in dw si lung equ ($-sir)/type sir ;registrul al in ax.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

Page 36: IOCLA

suntok: loop buclamica test bl, 0ffh jnz buclamare mov ax, 4c00h int 21hend start

lab9p2b.asm.model small.data sir db 023h, 034h, 0ffh, 002h, 001h, 0abh, 034h ;pt cuvant se modifica db in dw si lung equ ($-sir)/type sir ;registrul al in ax, bl in bx.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 21hend start

Page 37: IOCLA

lab9p2c.asm.model small.data sir dw 023h, 034h, 0ffh, 002h, 0cbh, 0abh, 034h ;pt octet se modifica dw in dl si lung equ ($-sir)/type sir ;registrul ax in al.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 21hend start

lab9p3a.asm Definiţi proceduri şi programele ce le apelează, pentru inserarea/

eliminarea unui subşir dintr-un şir dat (transferul parametrilor la proceduri se

face prin registre).

Page 38: IOCLA

.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

Page 39: IOCLA

int 21h.stack 100hend start

lab9p3b.asm.model small.data sir db 'alabalaportocala$' lung_sir equ ($-sir) sf_linie db 0dh,0ah,'$'.code elimina proc ;di adresa destinatiei add di, ax ;ax pozitia in destinatie push si ;cx lungimea dest, dx lungimea subsirului 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 100hend start

Page 40: IOCLA

lab9p4.asm Scrieţi un program pentru construirea unui şir, format din

caractere introduse de la tastatură, într-o zonă de memorie, şi care apoi să fie

tipărit direct şi invers, pe câte o linie nouă.

.model small

.data sir db 100 dup(?) lungmax equ ($-sir) sf_linie db 0dh,0ah,'$'.code tipareste proc push ax ;si inceputul sirului, cx lungimea sirului 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

Page 41: IOCLA

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 21hend start.stack 100h

lab9p5.asm Scrieţi programul care citeşte 2 şiruri de caractere, le depune în

memorie în format ASCIIZ, şi apoi le concatenează utilizând o procedură,

care primeşte prin registre adresele celor două şiruri sursă, şi a şirului

destinaţie (se presupune că sunt în acelaşi segment). Se va afişa şirul astfel

obţinut.

.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 ;di destinatia, cx lungimea maxima push ax cld mov ah, 1h bucla: int 21h cmp al, 0dh jz afara stosb loop bucla afara: mov al, 00h stosb pop ax

Page 42: IOCLA

ret citeste endp concat proc ;di sirul final, si sirul1, dx sirul2 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

Page 43: IOCLA

jmp bucla3 afara3: mov ax, 4c00h int 21hend start.stack 100h

lab9p6a.asm Scrieţi programul pentru citirea a 2 numere (ce vor fi depuse în

memorie în format zecimal împachetat, sau neîmpachetat), se vor aduna şi se

va afişa 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 ;di destinatia, cx lungimea maxima push ax ;intoarce cx lungimea citita 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

Page 44: IOCLA

citeste endp aduna proc ;di, si adresele de inceput ale sirurilor push ax cmp dx, cx ;dx, cx lungimile numerelor jge e_ok ;intoarce di inceputul rez, dx lungimea lui xchg di, si xchg dx, cx e_ok: ;di si dx contin numarul mai lung 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 ;testam transportul si depasirea pt. ultima adunare 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

Page 45: IOCLA

bucla3: ;si contine numarul, cx contine lungimea 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 21hend 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

Page 46: IOCLA

citeste proc ;di destinatia, cx lungimea maxima push ax ;intoarce cx lungimea citita 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 ;di, si adresele de inceput ale sirurilor push ax cmp dx, cx ;dx, cx lungimile numerelor

Page 47: IOCLA

jge e_ok ;intoarce di inceputul rez, dx lungimea lui xchg di, si xchg dx, cx e_ok: ;di si dx contin numarul mai lung 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 ;testam transportul si depasirea pt. ultima adunare 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

Page 48: IOCLA

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: ;si contine numarul, cx contine lungimea 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

Page 49: IOCLA

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