|
|
加入智力问答,难度会越来越大,也会越来越有趣哦,大家踊跃参与!!!!
|
| |
|
|
| |
|
|
[汇编程序]文件操作 |
| ;---------------------------------------------------------;用EDIT创建一个文本文件11.TXT,其中共有;9个字符“1、2、… 9”,编写一汇编程序,将;该文件中第5、6两个字符该改为由键盘键入;的任意两个字符后存盘;---------------------------------------------------------
code segment assume cs:code,ds:code org 100h start:jmp begin file db "d:\11.txt",0 handle dw ? buffer db 2 dup(?) ; 置2字节的缓冲区 msg1 db 'Unable to open 11.TXT!',0dh,0ah,'$' msg2 db 'Unable to seek 11.TXT!',0dh,0ah,'$' msg3 db 'Unable to read 11.TXT!',0dh,0ah,'$' count dw ? begin: mov ax,cs mov ds,ax ; 置DS=CS mov dx,offset file ; 置打开文件名地址 mov al,20 mov ah,3dh ; 打开文件 int 21h jc operr ; 不成功(CF=1)跳转 mov handle, ax ; 保存打开的读文件句柄 mov bx,handle mov count,-1 change: mov bx, handle mov dx,offset buffer ; 读缓冲区地址 mov cx, 1 ; 读1字节 mov ah,3fh ;从当前指针开始循序读文件 int 21h jc readeer ; 不成功(CF=1)跳转 inc count cmp count,4 je change1 cmp count,5 je change1 cmp ax,0 ; 是否到文尾? je close ; 是则转 mov bx,ax ; 读、写字节数 mov buffer[bx],'$' ; 串尾加上'$' mov dx,offset buffer ; 置缓冲区地址 call disp ; 显示读出的字串 jmp change ; 未到文件尾,再读 change1: mov bx,ax mov ah,01h int 21h dec bx mov buffer[bx],al mov bx,handle mov cx,0 mov dx,count ; 移动count个字 mov al,0 ; 从文首开始 mov ah,42h ; 移动读写指针 int 21h jc seekerr ; 不成功(CF=1)跳转 mov bx,handle mov cx,1 mov dx,offset buffer ; 置缓冲区地址 mov ah,40h ; 写文件 int 21h jmp change operr: mov dx,offset msg1 ; 显示打开文件错 call disp jmp done seekerr: mov dx,offset msg2 ; 显示移动指针错 call disp jmp close readeer: mov dx,offset msg3 ; 显示读文件错 call disp close: mov bx,handle ; 关文件 mov ah,3eh int 21h done: mov ah,4ch ; 结束 int 21h disp proc ; 显示过程 mov ah,09h int 21h ret disp endp code ends end start | |
|
|
|
| |
| ♀Links |
|
|