汇编网首页登录博客注册
masmaster的学习博客
博客首页博客互动【做检测题】论坛求助

我的博客

个人首页 |  我的文章 |  我的相册 |  我的好友 |  最新访客 |  文章收藏 |  论坛提问 |  友情链接 |  给我留言  
图片载入中
文章收藏

[2010-09-16 17:19] 习题4.34

图片载入中
编写一个能够复制文件的程序。源文件和目标文件由键盘输入。

答:
;----------------------------------------------------;
assume        cs:code,ds:data,ss:stack
data        segment
sfile        db        11 dup (0),0    ;源文件
dfile        db        11 dup (0),0    ;目的文件
buffer        dw        1024 dup (0)    ;缓冲区
shand        dw        0               ;源文件句柄
dhand        dw        0               ;目的文件句柄
fsize        dw        0               ;文件大小
errmsg        db        'Operate Failue!$'
data        ends
stack        segment stack           ;定义栈段
        dw 128 dup (0)
stack        ends
code        segment
start:
        mov ax,data             ;定义数据段
        mov ds,ax
;开始复制文件名        
        mov cx,0
        lea si,es:82h
        mov di,offset sfile
cp1:        mov al,es:[si]
        inc cx
        cmp al,20h
        jz jxcp
        mov [di],al
        inc si
        inc di
        jmp cp1
jxcp:
        lea si,es:82h
        add si,cx
        mov di,offset dfile
cp2:        mov al,es:[si]
        cmp al,0dh
        jz cpok
        mov [di],al
        inc si
        inc di
        jmp cp2
cpok:
;创建目的文件
        mov dx,offset dfile
        mov cx,0
        mov ah,3ch                ;creat destfile
        int 21h
        mov dhand,ax                ;save destFileHand
        jc err
;打开源文件
        mov dx,offset sfile
        mov cx,0
        mov ax,3d02h                
        int 21h
        mov shand,ax                                
        jc err
;获取文件大小
        mov ax,4202h                
        mov bx,shand
        int 21h
        jc err
        mov fsize,ax
        mov ax,4200h                 
        mov bx,shand
        int 21h
;读文件至缓冲区
        mov bx,shand
        mov cx,fsize                
        mov dx,offset buffer
        mov ah,3fh                
        int 21h
        jc err
;写目的文件
        mov bx,dhand
        mov cx,fsize                
        mov dx,offset buffer
        mov ah,40h                
        int 21h
        jc err
;关闭文件
        mov bx,shand
        mov ah,3eh
        int 21h
        jc err

        mov bx,dhand
        mov ah,3eh
        int 21h
        jc err
        jmp over
err:        mov dx,offset errmsg
        mov ah,9
        int 21h
over:        mov ah,4ch
        int 21h
code        ends
end        start
;----------------------------------------------------;
评论次数(0)  |  浏览次数(357)  |  类型(汇编习题集) |  收藏此文  | 
 
 请输入验证码  (提示:点击验证码输入框,以获取验证码