Re: opening and reading a character from a file with emu8086 assembler
- From: Frank Kotler <spamtrap@xxxxxxxxxx>
- Date: Sat, 24 Sep 2005 20:10:54 +0000 (UTC)
spamtrap@xxxxxxxxxx wrote:
mov cx,1 ;read one character at a time print: mov ah,3fh ;read from the opened file (its handler in bx) int 21h jc terminate ;end program if end of file is reached mov ax,dx ;char is in dl, send to ax for printing (char is in al)
Your problem is that int 21h/3Fh doesn't read a character into dl, it reads a character (cx characters, actually) into a buffer pointed to by dx. You'll need to allocate a buffer, with your other data, "input_buffer db 0", then, before the read, "mov dx, offset input_buffer". Now the int 21h/3Fh will put a character in the buffer - you'll have to get it into al for the int 10h/0Eh - "mov al, [input_buffer]" (the "[]"s are optional - I like 'em for "clarity"). I think that'll solve your problem...
Mmmm, maybe not... It isn't an error to read past the end of a file, so the "jc terminate" will never happen. If there's no error, ax contains the number of bytes actually read. So leave the "jc terminate" where it is (we still want to exit on error), and follow it with:
or ax, ax ; set flags according to ax jz terminate
*That'll* solve your problem... or get you closer, anyway :)
Best, Frank
.
- References:
- Prev by Date: Re: opening and reading a character from a file with emu8086 assembler
- Next by Date: Re: opening and reading a character from a file with emu8086 assembler
- Previous by thread: opening and reading a character from a file with emu8086 assembler
- Next by thread: Re: opening and reading a character from a file with emu8086 assembler
- Index(es):
Relevant Pages
|