flat assembler
Message board for the users of flat assembler.

Index > DOS > The program can create and write a file.

Author
Thread Post new topic Reply to topic
heythomas



Joined: 14 Aug 2008
Posts: 3
Location: California,San Francisco,USA
heythomas
Hello,everybody!
I am a new hand of FASM.I am very happy that I could make a program to creat and write a file yesterday.So,I write this message to share this code with the new hands of FASM.If there is something wrong in this code,please forgive me.
Code:
ORG 100H             ;Tell to the compiler that you want to get a *.com program.
;Create File:
MOV AH,3CH         ;Use INT 21H and AH=3CH to createe a file and get it's file handle.
MOV CX,0            ;0-Normal,1-ReadOnly,2-Hide,3-ReadOnly&Hide,4-System,5-System&ReadOnly,6-System&Hide,7-System&ReadOnly&Hide
MOV DX,FILENAME;Pass the string of the filename to DX.It means the program passes the filename to DS:DX.
INT 21H
;If you just want to open the file and not create the file,you can replace the CREAT FILE CODE with the following code.
;Open File:
;MOV AH,3DH         ;Use INT 21H and AH=3DH to open a file and get it's file handle.
;MOV AL,1             ;When AL=0,it will read a file.
                          ;When AL=3,it will read or write a file.
;MOV DX,FILENAME ;Pass the string of the filename to DX.It means the program passes the filename to DS:DX.
;INT 21H               ;Do as we command:open the file,and ask for the file handle.
                         ;If we succeeded,we can get the file handle from AX.
                         ;If we failed,we can get the ERROE CODE from AX.
MOV BX,AX          ;Now,we had better copy the file handle to BX.Because we will write a file soon and BX's function is storing the file handle.
;Write File:
MOV AH,40H        ;Use INT 21H and AH=40H to write a file.
MOV CX,11          ;This is the length of the string.
MOV DX,STR1      ;Pass the string yo DX.It means the program passes the string to DS:DX and write it to your file.
INT 21H              ;Do as we command:write the string to the file we want to write.
                         ;If we succeeded,we can get the real length of the string from AX.
                         ;If we failed,we can get the ERROE CODE from AX.
;Close File:
MOV AH,3EH        ;Use INT 21H and AH=3EH to close a file.
INT 21H              ;Do as we command:close the file.
                         ;If we failed,we can get the ERROE CODE from AX.
;Exit:
MOV AX, 4C00H   
INT 21H              ;Exit
 
FILENAME DB 'D:\TEST.TXT',0
STR1 DB 'HELLO WORLD'
    
Post 15 Aug 2008, 13:49
View user's profile Send private message MSN Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17450
Location: In your JS exploiting you and your system
revolution
Good job.
Post 15 Aug 2008, 17:05
View user's profile Send private message Visit poster's website Reply with quote
rCX



Joined: 29 Jul 2007
Posts: 166
Location: Maryland, USA
rCX
Nice! It looks just like my code when I was starting to learn asm! Razz
Post 15 Aug 2008, 19:31
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
...a few years later...
[Intro sound]
-there are no comments
-all the caps are small
-there is tons of more code

and the saga continues...

_________________
My updated idol Very Happy http://www.agner.org/optimize/
Post 16 Aug 2008, 20:32
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger 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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.