Int 21H [1.0] Function 16H (22) Create file

Creates a new directory entry in the current directory or truncates any existing file with the same name to zero length. Opens the file for subsequent read/write operations.

Call with:

AH = 16H

DS:DX = segment:offset of unopened file control block

Returns:

If function successful (file was created or truncated)

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 (directory full)

AL = FFH

Notes:

Since an existing file with the specified name is truncated to zero length (i.e., all data in that file is irretrievably lost), this function must be used with caution.

If this function is called with an extended file control block (FCB), the new file may be assigned a special attribute, such as hidden or system, during its creation by setting the appropriate bit in the extended FCB's attribute byte.

Since this function also opens the file, a subsequent call to Int 21H Function 0FH is not required.

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

[2.0+] Int 21H Functions 3CH, 5AH, 5BH, and 6CH, which provide 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 user must have Create rights to the directory that will contain the new file.

Example:

Create a file in the current directory using the name in the file control block myfcb.

myfcb db 0 ; drive = default

db 'QUACK ' ; filename, 8 chars

db 'DAT' ; extension, 3 chars

db 25 dup (0) ; remainder of FCB

.

.

.

mov ah,16h ; 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 create failed

.

.

.