汇编菜鸟提问!
本学期开汇编课,学期末要求做课程设计,老师透露说估计就四个题目中任选一个,1.dos的copy命令 2.dos的type命令 3.任意进制转码 4.简单动画
我选了COPY先做了。可是我发觉我的程序中对文件的处理不好,拷贝一个1.4k的文件,拷贝出来的文件竟然有32m。希望有高手指点一下。
源码如下:
lfcr macro
mov ah,06h
mov dl,0ah
int 21h
mov ah,06h
mov dl,0dh
int 21h
endm
;
scrview macro x
local goon
mov ah,09h
lea dx,message&x
int 21h
lea si,path&x
l&x: mov ah,01h
int 21h
mov [si],al
inc si
cmp al,08h
jne goon
dec si
push ax
push dx
mov ah,06h
mov dl,20h
int 21h
pop dx
pop ax
goon: cmp al,0dh
jne l&x
dec si
mov al,0
mov [si],al
lfcr
endm
;
openf macro
mov al,00
mov ah,3dh
lea dx,path1
int 21h
jc temp
mov flag1,ax
endm
;
creatf macro
mov ah,3ch
mov cx,00
lea dx,path2
int 21h
jc temp
mov flag2,ax
endm
;
mvdata macro
mov ah,3fh
lea dx,buf
mov bx,flag1
mov cx,512
int 21h
jc temp
mov ah,40h
lea dx,buf
mov bx,flag2
mov cx,512
int 21h
jc temp
cmp ax,512
jl l4
push cx
push dx
endm
;
mvp1 macro
mov ah,42h
mov cx,00
mov dx,512
push cx
push dx
mov al,00
mov bx,flag1
int 21h
jc temp
mov ah,42h
pop dx
pop cx
mov al,00
mov bx,flag2
int 21h
jc temp
endm
;
mvp2 macro
mov ah,42h
add dx,512
adc cx,00
push cx
push dx
mov al,00
mov bx,flag1
int 21h
jc temp
mov ah,42h
pop dx
pop cx
mov al,00
mov bx,flag2
int 21h
jc temp
jmp l3
endm
;
closef macro x
mov ah,3eh
mov bx,flag&x
int 21h
jc error
endm
;
data segment
message1 db 'Enter the full path of the file:$'
path1 db 64h dup(0)
flag1 dw ?
message2 db 'Enter the new path:$'
path2 db 64h dup(0)
flag2 dw ?
buf db 1000 dup(0)
message3 db 'Error!$'
;
data ends
stack1 segment para stack
sta db 10 dup(0)
stack1 ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
scrview 1
scrview 2
openf
creatf
mvdata
mvp1
jmp l3
temp: jmp error
l3: mvdata
mvp2
l4: closef 1
closef 2
jmp l5
error: mov ah,09h
lea dx,message3
int 21h
l5: mov ah,4ch
int 21h
code ends
end start
由于水平有限,我把出错代码检查忽略了,一概以出错代替。
问题点数:100、回复次数:2Top
1 楼wequal(小虾)回复于 2002-12-11 16:20:34 得分 100
;前不久我正好写了一个单文件copy的程序,希望能给你一点帮助。
;*******copy file program
;*******only use one file copy
;*******date create 2002/11/27:10:30
;*******use assembly masm5.0
;******* my program start ******
.model small
.data
NoPara db 'you must input source file and target file!!!'
SourceFile DB 40 DUP(?)
TargetFile DB 40 DUP(?)
buffer db 1024 dup(?)
flag db 1
succeed db '1 file(s) copied$'
ERROpen db 'Error open file ,no file be copied$'
ErrCrea db 'Error create file ,no file be copied$'
BadInput db 'You must input parameters$'
.code
.386
.startup
mov si,80h ;get parameter
xor cx,cx
mov cl,es:[si]
mov al,es:[si+1]
cmp al,0Dh
jz No_para ; No parameter
call GetParameter
mov ax,3d00h ;open a file
mov dx,offset SourceFile
int 21h
jc ErrorOpen
mov bx,ax
mov si,ax ;protect source file name
mov ah,3ch ;create a file
mov cx,0
mov dx,offset TargetFile
int 21h
mov di, ax ;protect target file name
jc ErrorCreate
ReadAgain:mov bx,si ;get source file name
mov ah,3fh ;read from file
mov cx,1024
mov dx,offset buffer
int 21h
; mov cx,1024
cmp ax,1024 ;if to file end
jz go_on
mov flag ,0
mov cx,ax
go_on: mov bx,di ;get target file name
mov ah,40h ;write into file
mov dx, offset buffer
int 21h
cmp flag,0
jnz ReadAgain
mov ah,3eh ;close source file
int 21h
pop bx
int 21h ;close target file
mov dx,offset succeed
mov ah,9
int 21h
jmp _end
ErrorOpen:mov dx,offset ErrOpen ;exit with error open file
mov ah,9
int 21h
jmp _end
ErrorCreate:mov dx,offset Errcrea ;exit with error create file
mov ah,9
int 21h
jmp _end
No_para: mov dx,offset BadInput ;exit with error bad input file
mov ah,9
int 21h
jmp _end
GetParameter proc
sub cx,2
mov si,82h
lea di,SourceFile ;Get Source File Name
again: mov al,es:[si]
mov [di],al
inc si
inc di
mov al,es:[si]
cmp al,20h
jz Next ;Get Target File Name
loop again
mov al,0
mov [di],al
ret
Next: mov al,0
mov [di],al
lea di,TargetFile
inc si
loop again
GetParameter endp
_end:
.exit
end
Top
2 楼buffoon(悠云[http://buffoon.blog.com.cn])回复于 2002-12-11 18:21:28 得分 0
谢谢wequal(无敌),有什么问题我再来请教。Top




