Chapter
1
I
System
Calls
Write to a File
or
Device
Function Call
40H
Transfers
a
specified number of bytes from a buffer into a file.
If
the number
of
bytes written
is
not the same as the number re-
quested, then an error has occurred.
If the number of bytes
to
be written is zero, the file size
is
set
to the current position. Allocation units are allo-
cated
or
released as required.
All I/O is done using normalized pointers; no segment
wrap-around will occur. MS-DOS takes the pointer you
specify in DS:DX and modifies it
so
that DX is OOOFH
or
smaller.
Entry Conditions:
AH
=
40H
DS:DX
=
pointer to buffer
CX
=
number of bytes to write
BX
=
file handle for
file
to write
Exit Conditions:
Carry set:
Carry not set:
Error Returns:
AX
=
6
AX
=
error
code
AX
=
number of bytes written
Invalid handle. The handle passed
rently open.
AX
=
5
in BX is not cur-
Access denied. The handle passed in BX was opened
in
a
mode that did not allow writing.
Example:
Write
equ
40H
Id5 dx,buffer
mov
cx ,count
mov
bx,
handle
mov
ah,
Wr
I
te
int
21
H
112