Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DOSSEG
- .MODEL TINY
- .STACK 100h
- .DATA
- inputFile DB 'input.txt',0
- outputFile DB 'output.txt',0
- error DB 'Error unable to open file.',0
- text DB 2000 DUP('$')
- buffer DB '2', '$'
- .CODE
- .386
- file_write macro str
- mov ah, 40h
- push bx
- mov bx, di
- mov cx, 1
- lea si, buffer
- mov [si], str
- mov dx, si
- int 21h
- pop bx
- endm
- start:
- mov ax, @Data
- mov ds, ax
- mov es, ax
- ; opening file
- mov ah, 3Dh
- mov al, 0
- lea dx, inputFile
- int 21h
- jc error_no_file
- mov si, ax
- ; reading
- lea dx, text
- reading_file:
- mov ah, 3Fh
- mov bx, si
- mov cx, 1
- int 21h
- inc dx
- cmp ax, 1
- je reading_file
- ; closing inputfile
- mov ah, 3Eh
- mov bx, si
- int 21h
- ; creating new file
- mov al, 1h
- mov ah, 3Ch
- mov cx, 0
- lea dx, outputFile
- int 21h
- mov di, ax
- ; main part
- mov cx, 0
- mov bx, OFFSET text
- mov dx, bx
- iter:
- cmp cx, 0
- je met
- add bx, 1
- met:
- mov cx, 1
- mov al, [bx]
- cmp al, 40h
- jbe nextword
- cmp al, 4Dh
- jbe print
- cmp al, 60h
- jbe nextword
- cmp al, 6Dh
- jbe print
- jmp nextword
- print:
- mov ah, 2
- mov dl, al
- int 21h
- file_write al
- cmp al, 20h
- jz iter
- znaki:
- cmp [bx + 1], ah
- jz printspace
- add ah, 1
- cmp ah, 30h
- jbe znaki
- add bx, 1
- mov al, [bx]
- cmp al, 13
- jz cancel
- jmp print
- nextword:
- cmp al, 20h
- jz iter
- add bx, 1
- mov al, [bx]
- cmp al, 13
- jz cancel
- jmp nextword
- printspace:
- mov ah, 2
- mov dl, 20h
- int 21h
- file_write 20h
- jmp iter
- cancel:
- mov ah, 2
- mov dl, 10
- int 21h
- ; closing outputFile
- mov ah, 3Eh
- mov bx, di
- int 21h
- mov ah, 4ch
- int 21h
- error_no_file:
- lea dx, error
- mov ah, 9h
- int 21h
- mov ah, 4ch
- int 21h
- end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement