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

📄 file.asm

📁 3.1 磁盘存取简介 3.1.1 利用FCB(文件控制块)存取磁盘文件: (2) 在程序的数据段设置FCB和DAT(数据传输区)。 (3) 利用DOS功能调用打开文件(读)或建立文件(写)
💻 ASM
字号:
	.MODEL SMALL
	.STACK 64
;******************************************
	.DATA
	
path db 'information.dat',00H
handle dw ?
handle2 dw ?

stringn db 30 
stringl db ?
string  db 30 dup (' '),0dh,0ah

stringzero db 30 dup (' '),0dh,0ah;help string to bacame zero
stringpp db 'please input you table in this form:"id(tab)name(tab)mark',13,10,'$'
stringpt db 'choose what you want.  R.read  W.write  Q.quit',13,10,'$'

stringinfo db 'give the count you want to input:',13,10,'$'

stringal db 500 dup(' ')
reader db 500 dup(' '),'$' 

;******************************************
	.CODE

begin PROC FAR

	mov ax,@data
	mov ds,ax
	mov es,ax
	
next:	mov ah,09h
            mov dx,seg stringpt
            mov ds,dx
            mov dx,offset stringpt 
            int 21h
             
            mov ah,1
            int 21h

	cmp al,'q'
	je t 
	
	cmp al,'r'
	call crlf
	je r
		
w:	call input
	call creat
	call write
	call close	
	
	
r:	call open
	call read
	call write2	
	call close
	
;if you can't see the output,please take following two lines effect
			
	;mov ah,0AH
	;int 21h
	;return DOS
t:
	mov ax,4C00H
	int 21h
	
begin ENDP

;creat******************************************

creat proc near

	mov ah,3cH
	mov cx,00
	lea dx,path
	int 21H
	
	mov handle,ax
	
	ret	
creat endp

;***********************************************

;write*******************************************

write proc near
	
	mov ah,40h
	mov bx,handle
	mov cx,500
	lea dx,stringal
	int 21h
		
	ret
write endp

;***********************************************

;close*******************************************

close proc near

	mov ah,3eh
	mov bx,handle
	int 21h
	
	jmp next
	ret
close endp

;***********************************************

;input*******************************************

input proc near
	 
	 mov ah,09h
             mov dx,seg stringinfo
             mov ds,dx
             mov dx,offset stringinfo 
             int 21h
             
             mov ah,1
             int 21h
             cbw
                          
             sub cx,cx
             sub al,30h
	 mov cl,al	 

             call crlf

             mov ah,09h
             mov dx,seg stringpp
             mov ds,dx
             mov dx,offset stringpp 
             int 21h
             
	mov bx,0;flag,to point the whole string's next copy position 
	 	                      	 	 
            again:
                     call zero
            
                     lea dx,stringn
                     mov ah,0ah
                     int 21h
                               
                     call delete                                   
                     call crlf	
		
                     call store
		
	         sub bx,32
                     loop again
                                                                            
	 ret	           
input endp

;***********************************************

;crlf********************************************

crlf proc near

	mov dl,0dh
   	mov ah,02h
   	int 21h
  	mov dl,0ah
   	mov ah,02h
   	int 21h
   	ret
   	
crlf endp

;***********************************************

;delete enter*************************************

delete proc near

	push cx
	push di
	push si

	mov al,20h
            lea si,string
            
            mov cl,stringl
           
            lea di,string
            add di,cx
	
	neg cx
	add cx,30
	      
            cld
            rep stosb
            
            pop cx
            pop di
            pop si
            
            ret
            
delete endp           
                     
;***********************************************                  

;zero********************************************

zero proc near

	push cx
	push di
	
            lea si,stringzero;put string zero
            lea di,string
	      
            mov cx,32
            cld
            rep movsb
            
            pop cx
            pop di
            
            ret
            
 zero endp           
                     
;***********************************************                  
                  
;store*******************************************

store proc near

	  push cx
	  push di
	 
	  lea si,string
              lea di,stringal
	 
              sub di,bx
              mov cx,32
              cld
              rep movsb
             
              pop cx
              pop di
             
              ret
             
store endp

;***********************************************

;open*******************************************

open proc near
	
	mov ah,3dh
	mov al,00
	
	lea dx,path
	int 21h
	
	mov handle2,ax	 
	ret
open endp 

;***********************************************

;read********************************************

read proc near

	push bx
	push dx
	
	mov ah,3fh
	mov bx,handle2
	mov cx,500
	
	lea dx,reader
	int 21h
	
	pop bx
	pop dx

	ret	
read endp

;***********************************************

;write2*******************************************		

write2 proc near

	push dx
	
	mov ah,09h;write	
            mov dx,offset reader
            int 21h
            
            call crlf
             
	pop dx
	
	ret
write2 endp
	
;***********************************************

END begin ;set entry point

⌨️ 快捷键说明

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