Function 40h Write File or Device
Writes bytes from a buffer to an open file or device.
Entry AH = 40h
BX = Handle of file or device
CX = Number of bytes to write (> 0)
DS:DX = Address of buffer
Return AX = Number of bytes written
or
AX = Error code, if CF is set
| 05h Access denied (file is read-only)
| 06h Invalid handle
──────────────────────────────────────────────────────────────────
This function writes data to the file or device whose handle is in
BX. When DOS writes to a file, it writes data starting at the
current location of the file pointer. When this function returns,
the file pointer is positioned at the byte immediately following
the last byte written to the file (i.e. incremented by the number
of bytes written).
A program can write bytes to anywhere in the file by calling
function 42h (LSEEK) to move to file pointer before writing data.
Writing 0 (zero) bytes truncates the file at the current position
of the file pointer.
If the number of bytes written is smaller than the number
requested, the destination file or disk is full. The carry flag is
not set in this situation.