Anda di halaman 1dari 4

Experiment No. 7 TITLE Simulation of DOS COPY command.

. AIM: - Write 8086 ALP to read command line arguments using PSP (Program Segment Prefix) and implement DOS COPY Command . Use File Handle function for handling the files. Handle all the errors and display appropriate message if user does not enter proper command line argument. OBJECTIVE: 1. To study PSP (Program Segment Prefix) & its use to read command line arguments to implement command line interface. 2. To study file handle DOS functions. THEORY: 1. PSP (Program Segment Prefix) A thorough understanding of the program segment prefix is vital to successful programming under MS-DOS. It is a reserved area, 256 bytes long, that is set up by MS-DOS at the base of the memory block allocated to a transient program. The PSP contains some linkages to MS-DOS that can be used by the transient program, some information MS-DOS saves for its own purposes, and some information MS-DOS passes to the transient program to be used or not, as the program requires. The Program Segment Prefix Structure

1. INT 21H, FUNCTION 3CH : CREATE FILE Creating a new file Call with AH is 3CH DS:DX is the address of filename (ASCIIZ) CX is attribute Bit Significance

0 read-only 1 hidden 2 system 3 volume label 4 reserved 5 archive 6-15 reserved Returns file handle in AX if successful or error code 3, 4, or 5 2. INT 21H, FUNCTION 3DH : OPEN FILE Opening an Existing file Call with AH is 3DH DS:DX is the address of filename (ASCIIZ) AL is access code 0 read 1 write 2 read/write Returns file handle in AX if successful or error code 2,4,5,12 3. INT 21H, FUNCTION 3EH : CLOSE FILE Closing a file frees the file handle and updates file info (size, timestamp) in directory. Call With: AH is 3EH BX is the file handle. Returns error code 6 in AX if unsuccessful. 4. INT 21H, FUNCTION 3FH : READ FILE If a file is open for reading, this function will copy a specified number of bytes from the file to a memory buffer. EOF is detected by comparing CX and AX after the read Call with: AH is 3FH BX is file handle CX is number of bytes to read DS:DX is address of buffer Returns number of bytes read in AX if successful or error code 5 or 6 5. INT 21H, FUNCTION 40H : WRITE FILE This function sends one or more bytes to a file that is open for output. A full disk will result in less than the specified number of bytes being written. Call with: AH is 40H BX is file handle CX is number of bytes to write DS:DX is address of bytes to be written Returns number of bytes written in AX if successful or error code 5 or 6.

6. INT 21H, FUNCTION 4EH : FIND FILE Number of arguments passed to command line are stored at location 80H in PSP and the actual arguments are stored at 81H location onwards. 2. List of Assembler directives used list as used in the program. 3. List of DOS functions used: Program uses File handle functions and for all file handle functions following terms are common & important. i. File Handle It is an integer assigned to a file by DOS. Used to refer to the file in programs. DOS provides file handle functions to manipulate files These are available through the DOS interrupt (21H) Predefined File HandlesDOS manages standard input output devices through these handles 0 keyboard (stdin) 1 screen (stdout) 2 error output (stderr) 3 auxiliary device 4 printer ii. File Errors Many file handling routines return an error code carry clear indicates no error carry set indicates an error AX will contain some output or an error code 1 invalid function number 2 file not found 3 path not found 4 no free handles 5 access denied 6 invalid handle C invalid access code F invalid drive 10 can't remove current directory 11 not the same device 12 no more files to be found Searches the default or specified directory on the default or specified drive for the first matching file. AH is 4EH CX is the search attribute DS:DX is the address of filename (ASCIIZ) Successful operation (CF=0) indicates file found or unsuccessful operation Returns error code in AX. 7. INT 21H, FUNCTION 5BH : CREATE FILE (Supported in version 3.0 and later) Creates a file and returns a handle that can be used by the program for subsequent access to the file. If a file with the same name already exists, the function fails. Call with: AH is 5BH CX is the attribute DS:DX is the address of filename (ASCIIZ)

Successful operation (CF=0) indicates file creation and returns file handle through AX or unsuccessful operation (CF=1) Returns error code in AX. 8. INT 21H, Function 62H : GET PSP BASE ADDRESS Obtains the segment address of the program segment prefix (PSP) for the currently executing program. Call with: AH is 62H Returns BX = segment address of the PSP MAIN ALGORITHM: 1. Get base address of PSP ( 62H function of DOS INT 21H ) 2. Check for required number of arguments i.e., 2. If there are invalid arguments, then display appropriate error message (No, insufficient or too many parameters) and terminate. 3. Get command line arguments i.e. Source filename & destination filename from PSP and store it in respective buffers. 4. Check whether source file exists (4EH function of INT 21H). If not display appropriate error message and terminate. 5. Check whether destination file exists (5BH function of INT 21H). if the file already exists (CF=1) ask user whether wants to overwrite? If yes, then create file using 3CH function otherwise terminate. 6. Open source file using 3DH function in read mode. Check for error in opening a file, if yes display appropriate error message and terminate. 7. Read the record from source file in a buffer using 3FH function. Check for error in reading file, if yes display appropriate message and terminate. 8. Check for end of source file by comparing AX (Bytes actually read) with 0, if equal (EOF) goto step 11. 9. Write the record ( with length = no. of bytes actually read in earlier read ) from buffer into the destination file using 40H function. Check for error in writing file, if yes display appropriate error msg. and terminate. 10. Go to step 7. 11. Close both the files (3FH function of INT 21H). 12. Safe termination and exit to DOS using 4CH function of INT 21H. Macros used: 1. Message: Message Macro Msg Purpose: It is used to display a message. Input: msg (dummy parameter) Output: It displays the message on the screen Procedures Used: None. Conclusion: DOS COPY command is successfully implemented in assembly with command line interface. Platform Used: DOS, MASM, LINK. References: Advanced MS DOS Programming by Ray Duncan

Anda mungkin juga menyukai