;********************************************************************************************** ;* * ;* LAB3-5.ASM - Assembler Laboratory ZMiTAC * ;* * ;* program that copies characters between files * ;* * ;********************************************************************************************** comment % ********************************************* * copy bytes from one file to other file * ********************************************* % .model small .stack 512 .data file1 db "filein.txt", 0 file2 db "fileout.txt", 0 .data? buffer db 1024 dup (?) .code start: mov ax, seg file1 mov ds, ax ; open input file mov dx, offset file1 ; DS:DX - ASCIIZ of filename mov ah, 3Dh ; open file mov al, 0 ; open for reading int 21h ; call DOS function jc open_error ; CF set -> error mov si, ax ; file handle in si ; create output file mov dx, offset file2 mov cx, 0 ; file attributes: none mov ah, 3Ch ; create file int 21h jc create_error ; CF set -> error mov di, ax ; file handle in di mov ax, seg buffer mov ds, ax copy_loop: mov dx, offset buffer ; read block mov bx, si ; source handle mov cx, sizeof buffer mov ah, 3Fh ; read data int 21h jc loop_error cmp ax, 0 jz loop_error ; nothing to write ; write block mov bx, di ; destination handle mov cx, ax mov ah, 40h ; write data int 21h jz loop_error ; write error ; write '*' mov ah, 02h mov dl, '*' int 21h ; write character jmp copy_loop loop_error: mov ah, 3Eh ; close output file mov bx, di int 21h create_error: mov ah, 3Eh ; close input file mov bx, si int 21h open_error: mov ax, 4C00h ; exit int 21h end start