⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 writefl.asm

📁 DOS下基于28f512的小型文件系统 format.asm/list.asm/erasetes.asm/readfl.asm/start.asm/writefl.asm
💻 ASM
字号:
port_a  equ 0c800h
port_b  equ 0c801h
port_d  equ 0c803h
port_ce equ 0c810h
data    segment
buffer db 0fc00h dup(?)
string1 db 0dh,0ah,'file path&name:','$'
string2 db 0dh,0ah,'file name to write:','$'
string3 db 0dh,0ah,'file name too long!','$'
string4 db 0dh,0ah,'error write!','$'
string5 db 0dh,0ah,'free room is not enough!','$'
string6 db 0dh,0ah,'error open file!','$'
string7 db 0dh,0ah,'error read file!','$'
filelen dw ?
filepath db 20 dup(0)
filename db 13 dup(0)
position db 2 dup(?)
posit_n  db 2 dup(?)
number   db ?
data    ends
code    segment
        assume cs:code,ds:data
start:  mov ax,data
        mov ds,ax
        lea si,filepath
        lea dx,string1
        call input
input1: lea dx,string2
        lea si,filename
        call input
        cmp cx,12
        jle next1
        lea dx,string3
        mov ah,09h
        int 21h
        jmp input1
next1:  call open             ;open file
        cmp di,1
        jz exit_a1
        call read_f
        cmp di,1
        jz exit_a1
        mov ah,3eh           ;close file
        int 21h
        mov dx,port_d         ;set control word
        mov al,80h
        out dx,al
        lea si,position       ;read address begin to write file
        mov bx,10h
next_p2:mov cx,[si]
        call readbyte
        inc si
        inc bx
        call readbyte
        dec si
        mov dx,[si]
        cmp dx,0ffffh
        jz next_p1
        inc bx
        jmp next_p2
next_p1:mov [si],cx      ;check free room
        mov di,0ffffh
        sub di,cx
        mov dx,filelen
        cmp di,dx
        ja  next2
        lea dx,string5
        mov ah,09h
        int 21h
        jmp exit_a1
next2:  add cx,dx             ;get new file position
        lea si,posit_n
        mov [si],cx           ;write file new position
        dec bx
        call writebyt
        cmp di,25
        jz exit_a1
        inc si
        inc bx
        call writebyt
        cmp di,25
        jz exit_a1
        lea si,number         ;read the number of files
        mov bl,80h
        jmp next_n2
exit_a1:jmp exit_a2
next_n2:mov cl,[si]
        call readbyte
        mov dl,[si]
        cmp dl,0ffh
        jz next_n1
        inc bl  
        jmp next_n2
next_n1:inc cl
        mov [si],cl
        call writebyt         ;write new number of files
        cmp di,25
        jz  exit_a2
        lea si,position       ;write file address
        mov bl,20h
        mov al,number
        dec al
        mul bl
        mov bx,ax
        add bx,110h
        call writebyt
        cmp di,25
        jz exit_a2
        inc si
        inc bx
        call writebyt
        cmp di,25
        jz exit_a2
        add bx,7               ;write filelen
        lea si,filelen
        call writebyt
        cmp di,25
        jz exit_a2
        jmp below
exit_a2:jmp exit_a
below:  inc si
        inc bx
        call writebyt
        cmp di,25
        jz exit_a
        sub bx,19h             ;filename address
        lea si,filename        ;write filename
again1: mov cl,[si]            ;whether filename over?
        cmp cl,0
        jz  next3
        call writebyt
        cmp di,25
        jz  exit_a
        inc si
        inc bx
        jmp again1
next3:  mov bl,position      ;write file
        mov bh,position+1
        lea si,buffer
        mov cx,filelen
again2: call writebyt
     ;   cmp di,25
     ;   jz exit_a
        inc si
        inc bx
        loop again2
exit_a: mov ah,4ch           ;return dos
        int 21h
;
input   proc
        mov ah,09h
        int 21h 
        mov cx,0
again_i:mov ah,01h
        int 21h
        cmp al,0dh
        jz exit_i
        mov [si],al
        inc si
        inc cx
        jmp again_i
exit_i: ret
input   endp
;
open    proc
        lea dx,filepath
        mov al,00
        mov ah,3dh
        int 21h
        jnc next_o
        lea dx,string6
        mov ah,09h
        int 21h
        mov di,1
next_o: mov bx,ax
        ret
open    endp
;
read_f   proc
        mov cx,0fc00h
        lea dx,buffer
        mov ah,3fh
        int 21h
        jnc next_r
        lea dx,string7
        mov ah,09h
        int 21h
        mov di,1
next_r: mov filelen,ax
        ret
read_f   endp
;
readbyte proc

        mov dx,port_ce   ;read cmd
        mov al,00h
        out dx,al
        mov dx,port_b   ;addressh
        mov al,bh
        out dx,al
        mov dx,port_a   ;addressl
        mov al,bl
        out dx,al
        mov dx,port_ce   ;read
        in al,dx
        mov [si],al
        ret
readbyte endp
;
writebyt proc         ;address: bx, byte to write: [si]
        push cx
        mov di,0
next_w: mov dx,port_ce    ;set write cmd
        mov al,40h
        out dx,al
        mov dx,port_b    ;addressh
        mov al,bh
        out dx,al
        mov dx,port_a     ;addressl
        mov al,bl
        out dx,al
        mov dx,port_ce     ;write
        mov al,[si]
        out dx,al
        call delay
        mov dx,port_ce     ;write check
        mov al,0c0h
        out dx,al
        call delay
        mov dx,port_ce     ;read
        in al,dx
        cmp al,[si]
        jz exit_w
        inc di
        cmp di,25
        jnz next_w
        lea dx,string4     ;error write
        mov ah,09h
        int 21h
exit_w: pop cx
        ret
writebyt endp
;
delay   proc
        push cx
        mov cx,1000h
        loop $
        pop cx
        ret
delay   endp

code    ends
        end start

⌨️ 快捷键说明

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