[comp.os.msdos.programmer] Using DOS INT21 to read from a file

jdb@reef.cis.ufl.edu (Brian K. W. Hook) (02/04/91)

I am using TASM and TC++ to try and read from a file in section of code
of mine.  I am using inline assembly....

char c[2];

asm {
	mov ah, 3FH
	mov bx, fhandle
	mov cx, 0001H
	mov dx, c
	int 21
}

Now fhandle is 0 for stdin, I am just trying to read a single character.
I want to use the DOS INT instead of read or fread since I want my code
as small as possible.

AX returns 86C0, which is REALLY wrong.  AX should be the number of bytes
read or at least an error code....what am I doing wrong?

Thanks,

Brian

Ralf.Brown@B.GP.CS.CMU.EDU (02/04/91)

In article <26647@uflorida.cis.ufl.EDU>, jdb@reef.cis.ufl.edu (Brian K. W. Hook) wrote:
}asm {
}        mov ah, 3FH
}        mov bx, fhandle
}        mov cx, 0001H
}        mov dx, c
}        int 21
}}
}
}AX returns 86C0, which is REALLY wrong.  AX should be the number of bytes
}read or at least an error code....what am I doing wrong?

You forgot the 'h' in 'int 21h'....  Your code calls INT 15h, which returns
AH=86h on an unknown function.

--
{backbone}!cs.cmu.edu!ralf  ARPA: RALF@CS.CMU.EDU   FIDO: Ralf Brown 1:129/3.1
BITnet: RALF%CS.CMU.EDU@CMUCCVMA   AT&Tnet: (412)268-3053 (school)   FAX: ask
DISCLAIMER?  Did  | It isn't what we don't know that gives us trouble, it's
I claim something?| what we know that ain't so.  --Will Rogers

rkl@cbnewsh.att.com (kevin.laux) (02/04/91)

In article <26647@uflorida.cis.ufl.EDU>, jdb@reef.cis.ufl.edu (Brian K. W. Hook) writes:
> char c[2];
> 
> asm {
> 	mov ah, 3FH
> 	mov bx, fhandle
> 	mov cx, 0001H
> 	mov dx, c
		^^^
 ***	mov dx, OFFSET c
 ***	push ds
 ***	mov ds, SEG c
> 	int 21
 ***	pop ds
> }
> 
> AX returns 86C0, which is REALLY wrong.  AX should be the number of bytes
> read or at least an error code....what am I doing wrong?

	You haven't properly specified the buffer address.  You don't want
to move the contents of c to the DX register.  See above.

	The Carry Flag must be checked after the call.  If it is set then
AX will contain the error code.  Otherwise AX will contain the number of
bytes read.

	You really should RTFM more carefully.

-- 
________________________________________________________________________________
	R. Kevin Laux				Email: rkl1@hound.att.com
	AT&T Bell Labs				Voice: (908) 949-1160
	Holmdel, NJ 07733			Fax:   (908) 949-0959

valley@uchicago (Doug Dougherty) (02/05/91)

rkl@cbnewsh.att.com (kevin.laux) writes:

> ***	pop ds
>> }
>> 
>> AX returns 86C0, which is REALLY wrong.  AX should be the number of bytes
>> read or at least an error code....what am I doing wrong?

>	You haven't properly specified the buffer address.  You don't want
>to move the contents of c to the DX register.  See above.

>	The Carry Flag must be checked after the call.  If it is set then
>AX will contain the error code.  Otherwise AX will contain the number of
>bytes read.

>	You really should RTFM more carefully.


Ask Manuel.  He knows everything...

lbr@holos0.uucp (Len Reed) (02/09/91)

In article <26647@uflorida.cis.ufl.EDU> jdb@reef.cis.ufl.edu (Brian K. W. Hook) writes:
=I am using TASM and TC++ to try and read from a file in section of code
=of mine.  I am using inline assembly....
=
=char c[2];
=
=asm {
=	mov ah, 3FH
=	mov bx, fhandle
=	mov cx, 0001H
=	mov dx, c
=	int 21
=}
=
=Now fhandle is 0 for stdin, I am just trying to read a single character.
=I want to use the DOS INT instead of read or fread since I want my code
=as small as possible.

This is misguided.  Read support is probably already pulled
in by the startup code or something else you did.  Maybe not, though.
Still, this seems a poor reason to use in-line assembly.  There may
be lower level access to this function in the TCC library.  (Microsoft
C has _dos_read, for example.)

=AX returns 86C0, which is REALLY wrong.  AX should be the number of bytes
=read or at least an error code....what am I doing wrong?

I don't know Turbo C.  I assume that "mov dx,c" will move the address of
c (in the C style of using an array name as the address of the array).
If not, you may need lea (load effective address).  I assume that DS
is set up properly; presumably this is a small model program.

Are you really doing "int 21" and not "int 21h"?  If so, you're actually
calling 15h with AH == 3Fh, which is who knows what.
-- 
Len Reed
Holos Software, Inc.
Voice: (404) 496-1358
UUCP: ...!gatech!holos0!lbr