main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,ax mov ah,3ch ;建立文件 mov cx,20h lea dx,fn int 21h jc error mov fh,ax ;获取文件代号 lea dx,buff1 mov ah,40h ;写文件 mov bx,fh mov cx,6 int 21h jc error lea dx,buff2 mov ah,40h mov bx,fh mov cx,6 int 21h jc error mov ah,3eh ;关闭文件 mov bx,fh int 21h
error:
exit: mov ah,4ch int 21h
mainendp s3 ends
end main
22.从键盘上输入文本文件:“d:\\temp.txt”的内容后,然后新建一个文件“d:\\temp2.txt”,把
前一个文件的所有内容复制到后一个文件中
s1 segment stack
dw 100h dup(?) top label word s1 ends
s2 segment
f1 db 'd:\\temp1.txt',0 fd1 dw ?
f2 db 'd:\\temp2.txt',0 fd2 dw ?
buff1 db 50,?,50 dup(?) buff2 db 50 dup('$')
h1 db 'Please input a string: ','$' s2 ends
s3 segment
assume cs:s3,ds:s2,ss:s3 main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,ax
mov ah,3dh lea dx,f1 int 21h jnc l jmp error l: mov fd1,ax
lea dx,h1 mov ah,9 int 21h lea dx,buff1 mov ah,0ah int 21h
lea dx,buff1[2]
mov ah,40h ;写文件 mov bx,fd1 mov ch,0
mov cl,buff1+1 int 21h jc error
mov ah,3ch ;建立文件 lea dx,f2 mov cx,20h int 21h jc error mov fd2,ax
mov ah,42h mov al,00 mov cx,0 mov dx,0 mov bx,fd1 int 21h
mov ah,3fh lea dx,buff2[2] mov bx,fd1 mov ch,0
mov cl,buff1+1 int 21h jc error
mov ah,40h lea dx,buff2[2] mov bx,fd2 mov ch,0
mov cl,buff1+1 int 21h jc error
mov ah,3eh mov bx,fd1 int 21h jc error
mov ah,3eh mov bx,fd2 int 21h jc error jmp exit
;移动文件指针;读文件 ;写文件 ;关闭文件 ;关闭文件
error:
exit: mov ah,4ch int 21h
mainendp s3 ends
end main
23.从键盘上输入一个十进制数,以十六进制数显示出来。要求子程序用寄存器参数传送方法
s3 segment
assume cs:s3
main proc far
repeat:
call decibin call crlf call binihex call crlf jmp repeat
main endp
decibin proc near
mov bx,0
newchar:
mov ah,1 int 21h sub al,30h jl exit cmp al,9d jg exit cbw
xchg ax,bx mov cx,10d mul cx xchg ax,bx add bx,ax
jmp newchar
exit: ret
decibin endp
binihex proc near
mov ch,4 rotate:
mov rol mov and add cmp jl add
printit:
mov mov int dec jnz ret
binihex endp
crlf proc
mov mov int mov mov int ret
crlf endp
s3 ends
end
cl,4 bx,cl al,bl al,0fh al,30h al,3ah printit al,7h dl,al ah,2 21h ch rotate near dl,0dh ah,2 21h dl,0ah ah,2 21h main