The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => 16 bit DOS Programming => Topic started by: stebra on November 17, 2007, 12:17:44 PM

Title: file creation
Post by: stebra on November 17, 2007, 12:17:44 PM
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.
Title: Re: file creation
Post by: Vortex on November 17, 2007, 12:45:56 PM
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]
Title: Re: file creation
Post by: Mark Jones on November 17, 2007, 07:08:46 PM
Hi Stebra, do you want to access this file from the DOS 16-bit land?
Title: Re: file creation
Post by: Vortex on November 17, 2007, 07:46:31 PM
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.
Title: Re: file creation
Post by: MichaelW on November 18, 2007, 01:45:14 AM
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

Title: Re: file creation
Post by: eek on November 18, 2007, 10:53:15 AM
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
Title: Re: file creation
Post by: eek on November 18, 2007, 12:37:20 PM
If you actually want to see whats going on then you can use this interpreter.

http://www.btinternet.com/~btketman/tutpage.html