Int 21H [1.0] Function 28H (40) Random block write

Writes one or more sequential records from memory to a file, starting at a designated file location.

Call with:

AH = 28H

CX = number of records to write

DS:DX = segment:offset of previously opened file control block

Returns:

AL = 00H if all requested records written

01H if disk full

02H if segment wrap

CX = actual number of records written

Notes:

The records are written (logically, not necessarily physically) to disk from memory at the current disk transfer area address, specified by the most recent call to Int 21H Function 1AH. If the size and location of the buffer are such that a segment overflow or wraparound would occur, the function fails with a return code of 02H.

The file location of the data to be written is determined by the combination of the relative-record field (offset 21H) and the record-size field (offset 0EH) of the FCB. The default record size is 128 bytes.

After the disk transfer is performed, the current block (offset 0CH), current record (offset 20H), and relative-record (offset 21H) fields of the FCB are updated to point to the next record in the file.

If this function is called with CX = 0, no data is written to the disk but the file is extended or truncated to the length specified by combination of the record-size (offset 0EH) and the relative-record (offset 21H) fields of the FCB.

Compare with Int 21H Function 22H, which transfers only one record per function call and does not update the FCB relative-record field.

[3.0+] If the program is running on a network, the user must have Write access rights to the directory containing the file to be written.

Example:

Write four 1024-byte records, starting at record number 8, to disk from the buffer named buff, using the file control block myfcb.

myfcb db 0 ; drive = default

db 'MYFILE ' ; filename, 8 chars

db 'DAT' ; extension, 3 chars

db 25 dup (0) ; remainder of FCB

buff db 4096 dup (?) ; buffer for data

.

.

.

; set DTA address

mov ah,1ah ; function number

mov dx,seg buff ; address of buffer

mov ds,dx

mov dx,offset buff

int 21h ; transfer to MS-DOS

; set relative-record number

mov word ptr myfcb+21h,8

mov word ptr myfcb+23h,0

; set record size

mov word ptr myfcb+0eh,1024

; write the records

mov ah,28h ; function number

mov cx,4 ; number of records

mov dx,offset myfcb ; address of FCB

int 21h ; transfer to MS-DOS

or al,al ; check status

jnz error ; jump if write error

.

.

.