ALP to simulate COPY command using PSP

, by Engineer's Vision


;ALP to simulate COPY command using PSP


.MODEL SMALL
DISP MACRO MSG
        LEA DX,MSG
        MOV AH,09H
        INT 21H
ENDM

.DATA
        MSG1 DB 10,13,"INVALID NAME !!!!!!!!!$"
        MSG2 DB 10,13,"FILE 1----NAME IS INVALID!!!!!!!$"
        MSG3 DB 10,13,"FILE 2----NAME IS INVALID!!!!!!!$"
        MSG4 DB 10,13,"CAN NOT OPEN.....$"
        MSG5 DB 10,13,"ERROR IN WRITING FILE.........$"
        MSG6 DB 10,13,"!!!!!!!!!SUCCESFULL!!!!!!!!!!!!!!$"
        MSG7 DB 10,13,"ERROR...$"
        msg8 db 10,13,"FILE EXIST ALREADY $"
        MSG9 DB 10,13,"2 nd FILE CREATED..$"

        ARR1 DB 25H DUP(0)
        ARR2 DB 25H DUP(0)
        ARR3 DB 100H DUP(0)

        COUNT DW ?
        FH1 DW ?
        FH2 DW ?

.CODE
        MOV AX,@DATA
        MOV DS,AX

        MOV AH,62H  ;DOS FUN GIVES SOURCE ADD OF PSP
        INT 21H


        MOV ES,BX   ;PSP OFFSET ADD TO ES

        MOV DI,0082H

        LEA SI,ARR1

        MOV BH,' '
        MOV CX,0000H

        CALL CHECKVALID

        CMP CH,08H
        JBE N1
        DISP MSG1
        JMP EXIT

N1:     CMP CL,03H
        JE N2
        DISP MSG2
        JMP EXIT

N2:     MOV CX,0000H
        LEA SI,ARR2
        INC DI
        MOV BH,0DH  ;ASCII VAL OF ENTER

        CALL CHECKVALID
        CMP CH,08H
        JBE N3
        DISP MSG1
        JMP EXIT

N3:     CMP CL,03H
        JE N4
        DISP MSG3
        JMP EXIT

;*********OPENING OF FILE 1**********

N4 :    MOV AH,3DH          ; FUNCTION FOR OPENING OF FILE

        MOV AL,02H          ; OPENES A FILE IN READ/WRITE MODE
        LEA DX,ARR1         ; LOAD EFFECTIVE ADDRESS
        INT 21H

        MOV FH1,AX      ; HANDLE OF FILE

        JNC N5             
               
        DISP MSG4
        JMP EXIT

;*********CALCULATING COUNT**********       
N5:     MOV AH,42H        ; FUNCTION FOR SETTING FILE POINTER
        MOV AL,02H        ; 02 SIGNIFIES END OF FILE
        MOV BX,FH1        ; HANDLE IN BX
        MOV CX,0000H      ; MSB OF OFFSET FROM START FO FILE
        MOV DX,0000H      ; LSB...........
        INT 21H        

        MOV COUNT,AX

        MOV AH,42H
        MOV AL,00H
        MOV BX,FH1
        MOV CX,0000H
        MOV DX,0000H
        INT 21H

;**********READING FILE 1************
 L7 :   MOV AH,3FH              ; FUNCTION FOR READING FILE
        MOV BX,FH1              ; HANDLE IN BX
        MOV CX,COUNT            ; NO. OF BYTES TO BE READ IN CX
        LEA DX,ARR3         ; OFFSET OF ARRAY IN WHICH FILE CONTENTS ARE TO BE STORED
        INT 21H

      JC EXIT

;**********CHECK IF FILE EXIST********
        MOV AH,3DH          ; FUNCTION FOR OPENING OF FILE

        MOV AL,02H          ; OPENES A FILE IN READ/WRITE MODE
        LEA DX,ARR2         ; LOAD EFFECTIVE ADDRESS
        INT 21H

        MOV FH2,AX      ; HANDLE OF FILE

        JC NXT            
        DISP MSG8       
        JMP NN
;********SETTING FILE PTR**********
NN:     MOV AH,42H        ; FUNCTION FOR SETTING FILE POINTER
        MOV AL,02H        ; 02 SIGNIFIES END OF FILE
        MOV BX,FH2        ; HANDLE IN BX
        MOV CX,0000H      ; MSB OF OFFSET FROM START FO FILE
        MOV DX,0000H      ; LSB...........
        INT 21H        
        JMP N7

;**********CREATE NEW FILE NO 2*********************
NXT:

        MOV AH,3CH                ;CREATE FILE........
        MOV CX,0000H
        LEA DX,ARR2
         INT 21H
        MOV FH2,AX
        DISP MSG9
        JNC N7
        DISP MSG7
        JMP EXIT
;*********WRITE DATA****************

N7:    
        MOV AH,40H
        MOV BX,FH2
        MOV CX,COUNT
        LEA DX,ARR3
        INT 21H

        JNC N8
        DISP MSG7
        JMP EXIT
N8:     DISP MSG6

;**********EXIT**********************

EXIT:   MOV AH,4CH
        INT 21H

CHECKVALID PROC NEAR
        L1:     MOV AH,ES:[DI]
                CMP AH,2EH     ;.OPERATOR
                JNE C1
                JMP L3

        C1:     MOV [SI],AH
                INC SI
                INC DI
                INC CH
                JMP L1

       L3:      MOV [SI],AH
                INC SI
                INC DI

       C2:      MOV AH,ES:[DI]
                CMP AH,BH
                JNE L4

                JMP GO
       L4:      MOV [SI],AH
                INC SI
                INC DI
                INC CL
                JNZ C2
       GO:      RET
ENDP
END

0 comments: