.model small
.data ;DATA SEGMENT
segm dw 00h
CNT DW 00H
fname db ' $'
buff db 100 dup(?)
msg1 db 10,13," FILE CREATED SUCCESSFULLY !!! $"
msg db 10,13," FILEIDS NOT CREATED !!! $"
msg2 db 10,13," TYPE THE TEXT AND PRESS @ TO STOP :$"
MSG4 DB 0AH,0DH,"$"
msg7 db 10,13," FILE CAN NOT BE READED !!! :$"
msg8 db 10,13," FILE CAN NOT BE CLOSED !!! :$"
msg6 db 10,13," FILE CAN NOT BE OPENED !!! :$"
msg9 db 10,13," FILE CAN NOT BE CREATED !!! :$"
msg10 db 10,13," READ FILE IS AS FOLLOWS !!! :$"
msg12 db 10,13," $"
FBUF DB ?
MENU db 10,13,"_________________________ MENU ____________________________"
db 10,13," "
db 10,13,"1] CREATE FILE "
db 10,13,"2] WRITE IN FILE "
db 10,13,"3] READ FILE "
db 10,13,"4] EXIT "
db 10,13," "
db 10,13,"PLEASE NETER YOUR CHOICE :$"
WRNG db 10,13,"WRONG CHOICE !!$"
CHOICE DB 00H
.code ;CODE SEGMENT
start:
mov ax,@data
mov ds,ax
;GET PSP SEGMENT ADDRESS
mov ah,62h
int 21h
mov es,bx
mov si,80h
mov cl,es:[si]
mov ch,00
dec cl
inc si
inc si
lea di,fname
back:mov bl,es:[si]
mov ds:[di],bl
inc di
inc si
dec cl
jnz back
mov cl,00h
mov ds:[di],cl ;STORE FILENAME IN "FNAME" BUFFER
MAIN: LEA DX,MENU
MOV AH,09H
INT 21H
MOV AH,01H ;ACCEPT CHOICE
INT 21H
MOV CHOICE,AL
CMP CHOICE,31H
JE CRE
CMP CHOICE,32H
JE WR
CMP CHOICE,33H
JE RD
CMP CHOICE,34H
JE END11
LEA DX,WRNG
MOV AH,09H
INT 21H
JMP MAIN
CRE: call create
JMP MAIN
WR:
call write
CALL CLOSE
JMP MAIN
RD: CALL OPEN
CALL READ
JMP MAIN
END11:JMP END1
;PROCEDURE TO CREATE FILE
CREATE PROC
mov ah,3ch ; FUNCTION TO CREATE FILE
lea dx,fname
mov cx,00h
int 21h
jc eRR4
mov segm,ax
mov ah,09h
lea dx,MSG12
int 21h
; SUCCESSFUL FILE CREATED
mov ah,09h
lea dx,MSG1
int 21h
RET
; ERROR IN FILE CREARION
ERR4: mov ah,09h
lea dx,MSG9
int 21h
ret
CREATE ENDP
; PROCEDURE TO WRITE IN TO FILE
WRITE PROC
mov ah,09h
lea dx,MSG2
int 21h
mov ah,09h
lea dx,MSG12
int 21h
LEA DI,BUFF
MOV BX,0000H
MOV AX,0000H
UP: MOV AH,01H
INT 21H
CMP AL,0DH
JNE UP2
MOV AH,02
MOV DL,0AH
INT 21H
MOV DL,0DH
INT 21H
MOV DL,0AH
MOV [DI],DL
INC DI
INC BX
MOV DL,0DH
MOV [DI],DL
INC DI
INC BX
UP2: CMP AL,'@'
JE STOP
MOV [DI],AL
INC DI
INC BX
JMP UP
; WRITE IN TO FILE
STOP : MOV AL,0
INC BX
MOV [DI],AL
; FUNCTION TO WRITE FILE
MOV AH,40H
MOV CNT,BX
MOV BX,SEGM
LEA DX,BUFF
MOV CX,CNT
INT 21H
RET
WRITE ENDP
OPEN PROC
; FUNCTION TO OPEN FILE
MOV AH,3DH
LEA DX,FNAME
MOV AL,0
INT 21H ; 0 FOR NORMAL MODE
JC ERR3
MOV SEGM,AX
RET
ERR3 :LEA DX,MSG6
MOV AH,09H
INT 21H
RET
OPEN ENDP
READ PROC ; PROCEDURE TO READ FILE
LEA DX,MSG10
MOV AH,09H
INT 21H
mov ah,09h
lea dx,MSG12
int 21h
BACK1:
MOV AH,3FH
MOV BX,SEGM
MOV CX,1
LEA DX,FBUF
INT 21H
JC ERR1
MOV DL,FBUF
CMP DL,0
JE STP
CMP DL,1AH
JE STP
MOV AH,02H
INT 21H
JMP BACK1
ERR1:LEA DX,MSG7
MOV AH,09H
INT 21H
STP:RET
READ ENDP
CLOSE PROC
mov ah,3eh
mov bx,segm
int 21h
jc err2
ret
ERR2:LEA DX,MSG8
MOV AH,09H
INT 21H
ret
CLOSE ENDP
end1:mov ah,4ch
int 21h
END
Wednesday, November 05, 2008
file-open create
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment