Sunteți pe pagina 1din 3

data segment

buffer db 25,?, 60 dup(' ')


spatiu db 1, 1, 1 dup(' ')
nume_fisier db "ourfile.txt", 0 ;numele fisierului (0-lasa un spatiu intre
myfile si handler)
handle dw ?
mesaj_rau db "Nu s-a putut deschide fisierul $"
mesaj db "Introduceti numele: $"
ends

stack segment
dw 128 dup(0)
ends

code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax

lea dx, mesaj


mov ah, 09h
int 21h

;citire numele meu-de la tastatura si afisare pe urmatoarea linie


mov dx, offset buffer
mov ah, 0Ah
int 21h

mov dl, 0Dh


mov ah, 02h
int 21h

mov dl, 0Ah


mov ah, 02h
int 21h

xor bx, bx
mov bl, buffer[1]
mov buffer[bx+4], '$'
mov dx, offset buffer + 2
mov ah, 9
int 21h

;deschidere fisier
mov al, 2
mov dx, offset nume_fisier
mov ah, 3dh
int 21h

jc eroare
mov handle, ax
jmp citire

eroare:
lea dx, mesaj_rau
mov ah, 09h
int 21h

citire:

call citire_din_fisier; citire din fisier

mov al, buffer


cmp al, 0Ah
je scriere
jmp citire

scriere:

mov bx, handle


mov dx, offset buffer+2
mov cl, buffer+1
mov ah, 40h
int 21h

linie_2: ;inlocuire cu spatii


call citire_din_fisier
cmp buffer,0Ah
jne inlocuire
jmp sfarsit

inlocuire:
; seek...
mov al, 1
mov bx, handle
mov cx, 0
mov dx, -1
mov ah, 42h
int 21h

;----------------scriere cu spatii-----------------
mov bx, handle
mov dx, offset spatiu+2
mov cl, spatiu+1
cmp buffer, 0Dh
je sfarsit
mov ah, 40h
int 21h

jmp linie_2

sfarsit:

; close file...
mov bx, handle
mov ah, 3eh
int 21h

mov ax, 4c00h ; exit to operating system.


int 21h
ends

proc citire_din_fisier
mov bx,handle
mov dx, offset buffer
mov cx, 1

mov ah, 3Fh


int 21h
ret
citire_din_fisier ENDP

end start

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