flat assembler
Message board for the users of flat assembler.

Index > DOS > Read / Write to file

Author
Thread Post new topic Reply to topic
adroit



Joined: 21 Feb 2010
Posts: 252
adroit 27 Feb 2010, 03:53
How do I write data to a file, that the user input into the console? Also, how do I read data from that file, and use the information in my program?

Here's a algorithm:

PROMPT "Enter name here: "
READ Name
STORE Name in File.txt
READ data from File.txt
PRINT data from text
;End-Of-Line

And now if the user input: John Doe, the program will store that into File.txt then read the data from that text file (which is John Doe), and then Print the data on screen

_________________
meshnix
Post 27 Feb 2010, 03:53
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 27 Feb 2010, 03:56
MeshNix: Do you have a list of the DOS int 0x21 services?

http://en.wikipedia.org/wiki/MS-DOS_API
Post 27 Feb 2010, 03:56
View user's profile Send private message Visit poster's website Reply with quote
adroit



Joined: 21 Feb 2010
Posts: 252
adroit 27 Feb 2010, 20:48
Sort of!
Thanks!
Post 27 Feb 2010, 20:48
View user's profile Send private message Reply with quote
cthug



Joined: 03 Apr 2009
Posts: 36
Location: /home/Australia
cthug 28 Feb 2010, 11:03
This is more complete and includes other Interrupts: Interrupt Jump Table.
Post 28 Feb 2010, 11:03
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 28 Feb 2010, 13:14
to read data from DOS files, i recommend to use this code:
Code:
fptr:
.off=0
.seg=2
.size=4
DOSread:
.call=0
.ptr=4
.name=8
.handle=12
        push eax ebx ecx edx edi esi ds
        mov edi,[esi+.ptr]
        mov edx,[esi+.name]   ; load the asciiz filename pointer
        mov edx,[edx]
        mov ax,3d00h         ; DOS open file
        int 21h
        jc .error             ; carry, then error
        mov [esi+.handle],ax
        mov bx,ax
        mov ax,[edi+fptr.seg]
        mov ds,ax
        mov dx,[edi+fptr.off] ; at [ds:dx]
        mov ah,3fh            ; will we load
        mov cx,0ffffh         ; ffffh bytes
        int 21h               ; from the file.
        jc .error             ; carry then error
        pop ds                ; restore ds
        mov [edi+fptr.size],eax   ; how long is the file, in bytes
        mov bx,[esi+.handle]
        mov ah,3eh            ; DOS close file
        int 21h
        jc .error
@@:
        pop esi edi edx ecx ebx eax
        ret
.error:
        mov word[esi+.handle],0
        mov eax,0
        jmp @b
    


it will open file withhandle, read from handle, and close file.
then, multiple file openings/ reopening are possible with a minimal effort.
Post 28 Feb 2010, 13:14
View user's profile Send private message Visit poster's website Reply with quote
adroit



Joined: 21 Feb 2010
Posts: 252
adroit 01 Mar 2010, 02:59
Ok. Thanks. I'll test it out and post
Post 01 Mar 2010, 02:59
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 17 Aug 2010, 19:56
Just a question. I see people doing this. What does it do, whats its purpose ?


Quote:

Code:
push eax ebx ecx edx edi esi ds 
    

Post 17 Aug 2010, 19:56
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 17 Aug 2010, 20:34
it is because every registers can be modified in the function.
and it is writen one by one because sometimes, pushes are added or deleted during modifications.

and to avoid particular precautions in user code, everything is saved.

i hope people answered your question. Wink
Post 17 Aug 2010, 20:34
View user's profile Send private message Visit poster's website Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 17 Aug 2010, 20:48
yeah, thanks people.

*thought* Man, people are peoplelish *thought*
Post 17 Aug 2010, 20:48
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.