Blogger news

Followers

Friday, February 21, 2014


ASSUME DS: DATA, CS: CODE

DATA SEGMENT
FILEC DB 'D:\MPLAB\SEM4.TXT$', 0                  ;FILEC array is declared to create a file SEM4.txt in D
; directory under MPLAB folder.
FILED DB 'D:\MPLAB\123.TXT$', 0                     ;FILED array is declared to delete a file123.txt which is
;already created  in D directory under MPLAB folder.
MSG1 DB 0AH, 0DH, 'FILE IS CREATED', '$'
MSG2 DB 0AH, 0DH, 'FILE IS NOT CREATED', '$'
MSG3 DB 0AH, 0DH,'FILE IS DELETED', '$'
MSG4 DB 0AH, 0DH,'FILE IS NOT DELETED', '$'
MSG5 DB 0AH, 0DH,'CREATED FILE IS : ', '$'
MSG6 DB 0AH, 0DH,'DELETED FILE IS : ', '$'
DATA ENDS                                                             ; end of data segment

DISP MACRO MSG                                                                   ; DISP macro definition starts
MOV DX, OFFSET MSG                                                         ; display the message whose offset is in DX
MOV AH, 09H                                                           ; using 09H with DOS 21H interrupt. 
INT 21H
ENDM                                                                        ; end of macro definition

CODE SEGMENT
START: MOV AX, DATA                                          ; data segment initialization
       MOV DS, AX
       MOV DX, OFFSET FILEC                                         ; DX: offset address of  FILEC array containing the drive,
;directory path and filename to be created.
       MOV CX, 00                                                       ; CX is cleared indicating no attributes for the file. (read only)
       MOV AH, 3CH                                                   ; service no. to create file with DOS 21H interrupt
       INT 21H                                                              ; file is created
       JC NOTCRE                                                                             ; if carry flag is set to 1, it indicates that file is not created,
; then jump to label NOTCRE
       DISP MSG1                                                          ; otherwise invoke the macro to display MSG1 (created)
       DISP MSG5                                                          ; invoke the macro to display MSG5  (created file is)
       DISP FILEC                                                                             ;invoke the macro to display FILEC array contents.
       JMP NEXT                                                                               ; jump to label NEXT to delete the file.
NOTCRE: DISP MSG2                                                                  ; invoke the macro to display MSG2  (file is not created)
NEXT:  MOV DX, OFFSET FILED                            ;DX: offset address of  FILED array containing the drive,
; directory path and filename to be deleted.
       MOV AH, 41H                                                    ; service number to delete a file with DOS 21 H interrupt
       INT 21H                                                              ; file is deleted
       JC NOTDEL                                                        ; if carry flag is set to 1, it indicates that file is not deleted,
                                                                                    ; jump to label NOTDEL
       DISP MSG3                                                          ; invoke the macro to display MSG3  (file is deleted)
       DISP MSG6                                                          ; invoke the macro to display MSG6  (deleted file is)
       DISP FILED                                                          ;invoke the macro to display FILED array contents.  
       JMP EXIT                                                             ; jump to label EXIT and terminate.
NOTDEL:DISP MSG4                                                            ; invoke the macro to display MSG4 (file is not deleted)
EXIT: MOV AH, 4CH                                               ; terminate the program
       INT 21H
CODE ENDS                                                             ; end of code segment
       END START                                                       ; end of program



Output:
D:\MASM> Masm 12a.asm;
D:\MASM> Link 12a.obj;

0 comments: