- [somniumchase] 我一运行就说没有数字 01/01 11:44
- [游客] 为什么啊 08/07 15:36
- [游客] 如果想快一些 就改下面这里 dx值改成1H delay: push ax 04/19 02:53
- [lshhjx] 注释在程序中很重要,楼主不知道吗? 12/08 13:40
- [biaggi] 看不明白,在下還須學習 11/06 08:11
- [游客] 我运行的时候直接显示Unkown filename跳出了- -请问怎么改 06/16 21:44
- [游客] 勿庸置疑,注释是好习惯。与人方便自己方便。 04/12 10:33
- [游客] 老实说,看着真心累呀! 04/07 18:37
- [游客] 很无语,初学者就多看书,不要动不动要别人注释,基础打好了,再自己注释,这样比别人帮你注释好得多 12/17 19:43
- [dgkepu] 初学者:不懂,希望有多点注释带着学习学习! 12/07 20:52
- [游客] windows 7是一个64Bit操作系统,它不兼容DOS,无法识别16Bit系统。重装系统wind 02/28 21:05
- [游客] windows 7是一个64Bit操作系统,它不兼容DOS,无法识别16Bit系统。重装系统wind 02/28 21:05
- [466987333] 你好,高手,我想请教一个问题。 我用的是win7操作系统,32位的,里面没有找masm目录,是不是 12/12 17:30
- [lanfioncc] 那个太高级了。。。我还有点看不懂。。不过谢谢!!! 11/27 11:23
- [yc2010] 实验16中的 table: dw sub1,sub2,sub3,sub4 可不可以改成呢? 09/11 09:08
- [yc2010] mov bl,ah mov bh,0 add bx,bx ----------->这里为 09/07 21:03
- [yc2010] 为什么要add bx,bx呢? 09/07 20:55
- [yc2010] 那是不是像table[bx],ds[bx]....等(内存单元)都是表示一个字节呢? 09/06 21:10
- [masmaster] 杨季文的《80X86汇编语言程序设计教程》 09/01 12:52
- [游客] to masmaster shl左移4位,那al传进来的4,5,6位背景色不就没了. 为什 09/01 11:00
[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
;----------------------------------------------------;
答:
;----------------------------------------------------;
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) |
类型(汇编习题集) |
收藏此文 |