file.asm

来自「汇编实验 小球碰壁」· 汇编 代码 · 共 55 行

ASM
55
字号
data_seg  segment   
          path      db        'c:\file.txt',0  ;file path
          digit     dw         ?               ;file digit
          dataw     db        3 dup(?)         ;data buffer
data_seg  ends
setfile   proc      near                       ;establish a new file
          lea       dx,path                    ;
          mov       cx,0
          mov       ah,3ch
          int       21h
          jnc       nexts
        nexts:
          mov       digit,ax                   ;save file digit
          ret
setfile   endp                                 ;open file
openfile  proc      near
          lea       dx,path
          mov       al,2
          mov       ah,3dh
          int       21h
          jnc       nexto                      ;if can not open then establish a new file
          call      setfile
        nexto:
          mov       digit,ax                   ;set the file pointer to file head
          mov       al,0
          mov       cx,0
          mov       dx,0
          mov       ah,42h
          int       21h
          ret
openfile  endp
closefile proc      near                       ;close file 
          mov       ah,3eh
          mov       bx,digit
          int       21h
          ret
closefile endp
readfile  proc      near                       ;read file content to data buffer
          lea       dx,dataw
          mov       bx,digit
          mov       cx,3
          mov       ah,3fh
          int       21h
          ret
readfile  endp
writefile proc      near
          lea       dx,dataw                   ;write data buffer content to data buffer
          mov       cx,3
          mov       ah,40h
          mov       bx,digit
          int       21h
          call      closefile
          ret
writefile endp

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?