Re: opening and reading a character from a file with emu8086 assembler



hi, yes but [dx] is not allowed in emu8086. so i figured out the
solution:

copy dx to bp on which [] is allowed.. then copy [bp] to ax. this is
working well.


thanks for the help!


Benjamin David Lunt wrote:
> <spamtrap@xxxxxxxxxx> wrote in message
> news:1127560389.208499.175090@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> > Hi! I am new to assembly. I am currrently writing a program that opens
> > a file, reads on character at a time and print each character on the
> > screen. It prints the '$' character in a seemingly infinite loop. Here
> > is my code:
> >
> > org 100h ;.com memory layout
> >
> > mov dx, offset file ;address of file to dx
> > mov al,0 ;openfile (read-only)
> > mov ah,3dh
> > int 21h ;call the interupt
> > jc terminate ;if error occurs, terminate program
> > mov bx,ax ;put handler to file in bx
> >
> > 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)
>
> This service does not return the character in DX. This service
> reads CX bytes to the buffer pointed to by ds:dx, so the character
> is at ds:[dx] which just so happens to be the first character of
> FILE below.
>
> As for printing '$', I think that dx just may be 0x0124, since the
> offset of FILE may be 0x0124.
>
> As for the infinite loop, the carry is not set at EOF. Check
> for ax == cx after the service. AX is returned as the amount
> of bytes actually read. If AX == CX, then EOF was not found
> upon trying to read a number of bytes. This doesn't mean that
> the current file posision isn't at the eof, it just means that
> eof was not encountered when trying to read CX bytes.
>
> > mov ah,0eh ;print character
> > int 10h
> > jmp print ;repeat if not end of file
> >
> > terminate:
> > ret
> >
> > file db "c:\input.txt",0
> > handle dw ?
>
> Ben
>
> --
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> Forever Young Software
> http://www.frontiernet.net/~fys/index.htm
> To reply by email, please remove the zzzzzz's
>
> Batteries not included,
> Some assembly required.

.



Relevant Pages

  • Re: String to integer
    ... detect the character that terminated a numerical field. ... Skipblks returns the char that getc will next return, or EOF. ... int skipwhite; ...
    (comp.lang.c)
  • Re: getline - sort of
    ... detect the character that terminated a numerical field. ... static int ignoreblks ... which may be \n or EOF ... Skipblks returns the char that getc will next return, ...
    (comp.lang.c)
  • Re: Building a simple command line interface
    ... detect the character that terminated a numerical field. ... static int ignoreblks ... which may be \n or EOF ... Skipblks returns the char that getc will next return, ...
    (comp.arch.embedded)
  • Re: User Input issue
    ... detect the character that terminated a numerical field. ... static int ignoreblks ... which may be \n or EOF ... Skipblks returns the char that getc will next return, ...
    (comp.lang.c)
  • Re: K&R 1.5.1 exercise
    ... Your while loop will eventually cause integer overflow, ... >> int main ... As EOF is a constant negative integer, you can start at INT_MIN and ... >>getcharcall will return the code of the first character you have typed ...
    (comp.lang.c)