Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- code_seg segment
- assume cs:code_seg, ds:code_seg,ss:code_seg
- org 100h
- ;============ macro ====================
- EM EQU 13
- NL EQU 10
- Space EQU 20h
- print_letter macro letter
- push AX
- push DX
- mov DL, letter
- mov AH, 02
- int 21h
- pop DX
- pop AX
- endm
- print_mes macro message
- local msg, nxt
- push AX
- push DX
- mov DX, offset msg
- mov AH, 09h
- int 21h
- pop DX
- pop AX
- jmp nxt
- msg DB message,'$'
- nxt:
- endm
- ;================ start of program ============
- ;================== read files =================
- start:
- ; read recoder file
- mov al, 2 ; open existing file
- mov dx, offset filename
- mov ah, 3dh
- int 21h
- jc error
- mov handle, ax; save descriptor
- jmp cont
- error:
- print_mes 'Cannot open Recoder.txt';
- int 20h
- cont:
- mov AH,3Fh; read
- mov BX, handle ; descriptor
- mov CX, 52*5; how much to read
- mov DX, offset bufDescr ; read here
- int 21h
- mov CX,AX ; Real readed
- ;close Recoder.txt
- MOV AH, 3Eh ;
- MOV BX, handle
- INT 21h
- ;=======================================================
- ; read file to recode
- print_mes 'Input File Name > '
- mov AH, 0Ah
- mov DX, offset FileName
- int 21h
- print_letter EM
- print_letter NL
- ;===============================================================
- xor BH, BH
- mov BL, FileName[1]
- mov FileName[BX+2], 0
- ;===============================================================
- mov AX, 3D02h ; Open file for read /write
- mov DX, offset FileName+2
- int 21h
- jnc openOK
- print_letter EM
- print_letter NL
- print_mes 'Cannot open Text.txt'
- int 20h
- ;===============================================================
- openOK:
- mov handle, ax
- print_letter EM
- print_letter NL
- print_mes 'Text.txt is opened'
- mov AH,3Fh; read
- mov BX, handle ; descriptor
- mov CX, 80; how much to read
- mov DX, offset bufFile ; read here
- int 21h
- mov CX,AX ; Real readed
- mov readed1, cx; copy readed
- ;============= end of reading files ============
- mov AX, 3D02h ; Open file for read /write
- mov DX, offset FileOutName
- int 21h
- mov handleOut, AX;
- jnc openOK1
- print_letter EM
- print_letter NL
- print_mes 'Cannot open TextOut.txt'
- int 20h
- openOK1:
- print_letter EM
- print_letter NL
- print_mes 'open TextOut.txt'
- ; change Text.txt
- mov BX, offset bufOut
- cycle:
- mov SI, offset bufFile
- cycle1:
- push CX;
- mov DL, byte ptr [SI]
- mov CX,52*5
- mov DI, offset bufDescr
- @:
- mov DH, byte ptr [DI]
- cmp DL, DH
- je change
- inc DI; go to next symbol in Recoder.txt
- inc DI
- inc DI
- inc DI
- inc DI
- loop @
- change:
- inc DI
- inc DI
- ; change symbol
- mov AL, byte ptr [DI]
- mov byte ptr [BX], AL
- inc BX
- inc SI; go to next symbol in file
- pop CX
- loop cycle1
- ;=================================================
- @cont:
- MOV AH, 40h ; Write in file function
- MOV BX, handleOut ; descriptor
- MOV CX, readed1 ; Number of writed bytes
- MOV DX, OFFSET bufOut ; Buffer adress
- INT 21h
- ; close files
- MOV AH, 3Eh ;
- MOV BX, handle
- INT 21h
- mov AH,3Eh
- mov BX, handleOut
- int 21h
- ;================ end of program ==============
- print_letter EM
- print_letter NL
- print_mes 'Program completed'
- ;output buffers after program
- print_letter EM
- print_letter NL
- print_letter EM
- print_letter NL
- mov AH, 09h
- mov DX, offset bufFile
- int 21h
- print_letter EM
- print_letter NL
- mov AH, 09h
- mov DX, offset bufout
- int 21h
- mov AX, 4c00h; exit function
- int 21h
- ;===================== data ====================
- bufDescr db 52*5 dup (' '),'$';
- bufFile db 80 dup (' ');
- DB '$'
- BufLen EQU $ - bufFile
- bufout db 80 dup (' ');
- BufLenOut EQU $ - bufOut
- DB '$'
- readed1 dw ?
- FileOut db "TextOut.txt",0
- File db 14,0,14 dup (0)
- filename db "Recoder.txt", 0
- FileOutName DB 'TextOut.txt',0
- handleOut dw ?
- handle dw ?
- code_seg ends
- end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement