Hello,
Can anyone inform me as to how i can store some generated data in a seperate file ?
If i call my file 'store.asm.'...........How indeed do i create and write data to it ?
Regards, Stebra.
This simple example creates a text file named text.txt :
.386
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
TEXT_LEN = 27
.data
text db 'This is a simple text file.'
filename db 'text.txt',0
.data?
hFile dd ?
_size dd ?
.code
start:
invoke CreateFile,ADDR filename,GENERIC_WRITE,\
0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,0
mov hFile,eax
invoke WriteFile,eax,ADDR text,TEXT_LEN,ADDR _size,0
invoke CloseHandle,hFile
invoke ExitProcess,0
END start
[attachment deleted by admin]
Hi Stebra, do you want to access this file from the DOS 16-bit land?
Hi stebra,
Sorry, I posted a 32-bit code example. int 21h is what you need to work in the 16-bit DOS environment to create files.
stebra,
For information on handling files under 16-bit DOS, see Dos.inc from the older MASM macros available here (http://www.masm32.com/board/index.php?topic=1998.msg15780#msg15780).
The macros are not well commented, and somewhat complex because they are coded to handle all the various memory models, but they should give you a good idea of what function calls to use, and you can get information on these function calls from Ralf Brown’s Interrupt list.
An HTML version is here:
http://www.ctyme.com/rbrown.htm
And the download version here:
http://www-2.cs.cmu.edu/~ralf/files.html
Been a while now, this is an old simple one of mine.
This download can be handy in the early stages.
http://coding.derkeiler.com/Archive/Assembler/comp.lang.asm.x86/2004-01/0491.html
http://cs.nyu.edu/~yap/classes/machineOrg/helppc/helppc21.zip
org cs:100
WB1
mov cx,0 ;
mov ah,3CÂ Â Â Â ;<create file F1
mov dx,F1
int 21
mov bx,ax    ;<file handle
mov ah,3DÂ Â Â Â ;<open file F1
mov al,02Â Â Â Â ;<read/write
mov dx,F1
int 21
mov bp,1
l1
mov ah,40Â Â Â Â ;<write B1 to file F1
mov al,00Â Â Â Â ;<bx has file handle
mov cx,2Â Â Â Â Â ;<loop to write B1
mov dx,B1
int 21
inc bp
cmp bp,FFÂ Â Â Â
jb l1
mov ah,3E
mov al,0
int 21
ret
;--------------------
F1 ch10 DB.TXT_
B1 db "001001"
ret
END
If you actually want to see whats going on then you can use this interpreter.
http://www.btinternet.com/~btketman/tutpage.html