Re: opening and reading a character from a file with emu8086 assembler
- From: "Benjamin David Lunt" <spamtrap@xxxxxxxxxx>
- Date: Tue, 27 Sep 2005 01:08:44 +0000 (UTC)
<spamtrap@xxxxxxxxxx> wrote in message
news:1127764694.935366.135340@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> hi, yes but [dx] is not allowed in emu8086. so i figured out the
> solution:
(smile) but for sure it is not allowed. Am I to do all of your
work? :)
> copy dx to bp on which [] is allowed.. then copy [bp] to ax. this is
> working well.
Please note that [bp] will use the stack segment by default
instead of the data segment as you would expect. It just
so happens that in your .COM program, ss = ds.
You could also use direct addressing
mov al,[buffer]
and not have to use a register at all.
> thanks for the help!
You're welcome.
Ben
> 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.
>
.
- Prev by Date: Re: Disassembling a DOS COM file
- Next by Date: Re: Clever ways to hide a compare
- Previous by thread: Re: opening and reading a character from a file with emu8086 assembler
- Next by thread: Figuring out table based encryption in assembly
- Index(es):
Relevant Pages
|