Re: opening and reading a character from a file with emu8086 assembler
- From: Dirk Wolfgang Glomp <spamtrap@xxxxxxxxxx>
- Date: Sat, 24 Sep 2005 20:27:54 +0000 (UTC)
spamtrap@xxxxxxxxxx schrieb:
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
You need a data-segment.
maybe: mov ax, cs mov ds, ax
For the beginning you need more stuff like:
Ralf Browns IRQ-List(RBIL) http://www.pobox.com/~ralf http://www.pobox.com/~ralf/files.html ftp://ftp.cs.cmu.edu/afs/cs.cmu.edu/user/ralf/pub/
RBIL->Inter61b.zip->Interrup.f INT 21 - DOS 2+ - "OPEN" - OPEN EXISTING FILE AH = 3Dh AL = access and sharing modes (see #01402) DS:DX -> ASCIZ filename
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 dx, OFFSET buffer
INT 21 - DOS 2+ - "READ" - READ FROM FILE OR DEVICE AH = 3Fh BX = file handle CX = number of bytes to read DS:DX -> buffer for data
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)
No, the byte is stored at ds:buffer.
mov dl, buffer
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 ?
^ You dont acess this location.
buffer DB ? ;-------------------
Dirk
.
- References:
- Prev by Date: Re: opening and reading a character from a file with emu8086 assembler
- 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
|