Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
ReadFile
◄Example► ◄Back► ◄Contents► ◄Index►
──────────────────────────────────────────────────────────────────────────────
;* ReadFile - Read from open file to specified buffer. See the CopyFile
;* procedure for another example of using DOS Function 3Fh to read files.
;*
;* Shows: DOS Function - 3Fh (Read File or Device)
;*
;* Params: handle - File handle
;* len - Number of bytes to read
;* pbuff - Pointer to buffer
;*
;* Return: Short integer with number of bytes read, or 0 if read error
ReadFile PROC \
USES ds di, \
handle:WORD, len:WORD, pbuff:PTR BYTE
LoadPtr ds, dx, pbuff ; Point DS:DX to buffer
mov di, dx ; Keep string offset in DI
mov bx, handle ; BX = handle
mov cx, len ; CX = number of bytes to read
mov ah, 3Fh ; Request DOS read
int 21h ; Read File or Device
jnc exit ; If ok, exit with bytes read
sub ax, ax ; Else set error code
exit: ret
ReadFile ENDP
-♦-