Chapter
1
I
System
Calls
Read
Read
from
a
File
or
Device Function Call
3FH
Transfers a specified number
of
bytes from
a
file into
a
buffer lo-
cation. It is not guaranteed that all bytes will be read. At most
1
line
of
text will be read from the keyboard. If the returned value
for number
of
bytes read is zero, then the program tried
to
read
from the end of file.
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
=
3FH
DS:DX
=
pointer
to
buffer
CX
=
number of bytes to read
BX
=
file handle for
the
file
to read
Exit Conditions:
Carry set:
Carry not set:
Error Returns:
AX
=
6
AX
=
error
code
AX
=
number of bytes read
Invalid handle. The handle passed in BX is not currently
open.
Access denied. The handle passed in BX was opened in
a
mode that did not allow reading.
AX
=
5
Example:
Read
equ
3FH
Ids dx,
buff
er
mov
cx, coun
t
mov
bx,handIe
mov
ah,Read
int
21
H
111