Re: opening and reading a character from a file with emu8086 assembler
- From: "Assembler Helper" <spamtrap@xxxxxxxxxx>
- Date: Mon, 26 Sep 2005 18:20:43 +0000 (UTC)
In previous example there should be:
JNE print ;repeat if not end of the buffer (instead of file).
and
mov al, buf ; char is in BUF... (and AL).
and the size of the buffer can be increased up to about 50k.
Here is a more general solution to open files of any length.
; ==========================================
; emu8086 version 4.00-Beta-12 or better is required!
; put file named "input.txt" to c:\emu8086\vdrive\c\
; (it's possible to copy "ReadMe.txt" and rename it or use any other
file that contains ASCII chars).
org 100h ; .com memory layout
mov dx, offset file ; address of file to dx
mov al,0 ; open file (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:
lea dx, BUF
mov ah,3fh ; read from the opened file (its handler in bx)
int 21h
CMP AX, 0 ; how many bytes transfered?
JZ terminate ; end program if end of file is reached (no bytes
left).
mov al, BUF ; char is in BUF, send to ax for printing (char is
in al)
mov ah,0eh ; print character (teletype).
int 10h
jmp print ; repeat if not end of file.
terminate:
mov ah, 0 ; wait for any key...
int 16h
ret
file db "c:\input.txt", 0
BUF db ?
END
; ==========================================
If you have any other questions feel free to e-mail:
pnp[at]emu8086[dot]com
.
- References:
- opening and reading a character from a file with emu8086 assembler
- From: spamtrap
- Re: opening and reading a character from a file with emu8086 assembler
- From: Assembler Helper
- opening and reading a character from a file with emu8086 assembler
- Prev by Date: Re: asm and nasm newbie
- Next by Date: Re: Figuring out table based encryption in assembly
- Previous by thread: Re: 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
|