opening and reading a character from a file with emu8086 assembler



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)
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 ?

so where is the bug?

.



Relevant Pages

  • Re: Arrow keys dont work in "read" command of bash
    ... readline is used ... used to remove any special meaning for the next character read ... The first character of delim is used to terminate the ... Display prompt on standard error, ...
    (comp.os.linux.misc)
  • Re: How to terminate a text file line in Unicode (in Java)
    ... stream encoding was set to »UTF-8«, what is the proper, best ... The primary question is how to terminate a line in Unicode. ... It does not define "the" line breaking character. ...
    (comp.std.internat)
  • Re: opening and reading a character from a file with emu8086 assembler
    ... reads on character at a time and print each character on the ... >> jc terminate;if error occurs, ... >> int 21h ... > As for the infinite loop, the carry is not set at EOF. ...
    (comp.lang.asm.x86)
  • Re: Field Independence in Normalised Tables
    ... only letters, numbers, and the underscore character. ... I have been reading about normalization. ... Employees hire and fire dates are a separate subset of data. ...
    (microsoft.public.access.tablesdbdesign)
  • Re: macro-reader
    ... identifier, it won't terminate that token, but will be incorporated ... into it as a constituent. ... Why \] is a terminating macro character and \} not. ... They can be in different readtables. ...
    (comp.lang.lisp)