Chapter
1
I
System Calls
Randomwrite
Random Write Function Call
22H
Performs a random write
of
a
record. The current block (offset
0CH) and current record (offset 20H) fields in the FCB are set
to
agree with the relative record field (offset 21H). The record ad-
dressed by these fields is then written from the Disk Transfer
Address. If the record size is smaller than a sector (512 bytes),
the records are buffered until
a
full sector is ready to write.
Entry Conditions:
AH
=
22H
DS:DX
=
pointer to the opened
FCB
of
the file to write
Exit Conditions:
If AL
=
00H, the write was completed successfully.
If AL
=
01H, the disk is full.
If AL
=
02H, there was not enough room at the Disk Transfer
Macro
Definition:
Address
to
write
1
record; the write was canceled.
wr
I
t
e-ran macro fcb
mov
dx,offsetfcb
mov
ah,22H
int
21
H
endm
Example:
The following program prompts for
a
letter, converts the letter
to
its alphabetic sequence
(A
=
1,
B
=
2, etc.), and then reads and
displays the corresponding record from a file named ALPHA-
BET.DAT on the disk in Drive B. After displaying the record, it
prompts the user to enter
a
changed record.
If
the user types
a
new record, it is written
to
the file; if the user presses
[ENTER],
the record is not replaced. The file contains 26 records; each re-
cord
is
28 bytes long.
71