Int 21H [1.0] Function 0FH (15) Open file

Opens a file and makes it available for subsequent read/write operations.

Call with:

AH = 0FH

DS:DX = segment:offset of file control block

Returns:

If function successful (file found)

AL = 00H

and FCB filled in by MS-DOS as follows:

drive field (offset 00H) = 1 for drive A, 2 for drive B, etc.

current block field (offset 0CH) = 00H

record size field (offset 0EH) = 0080H

[2.0+] size field (offset 10H) = file size from directory

[2.0+] date field (offset 14H) = date stamp from directory

[2.0+] time field (offset 16H) = time stamp from directory

If function unsuccessful (file not found)

AL = 0FFH

Notes:

If your program is going to use a record size other than 128 bytes, it should set the record-size field at FCB offset 0EH after the file is successfully opened and before any other disk operation.

If random access is to be performed, the calling program must also set the FCB relative-record field (offset 21H) after successfully opening the file.

For format of directory time and date, see Int 21H Function 57H.

[2.0+] Int 21H Function 3DH, which allows full access to the hierarchical directory structure, should be used in preference to this function.

[3.0+] If the program is running on a network, the file is opened for read/write access in compatibility sharing mode.

Example:

Attempt to open the file named QUACK.DAT on the default disk drive.

myfcb db 0 ; drive = default

db 'QUACK ' ; filename, 8 characters

db 'DAT' ; extension, 3 characters

db 25 dup (0) ; remainder of FCB

.

.

.

mov ah,0fh ; function number

mov dx,seg myfcb ; address of FCB

mov ds,dx

mov dx,offset myfcb

int 21h ; transfer to MS-DOS

or al,al ; check status

jnz error ; jump if open failed

.

.

.