News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

file creation

Started by stebra, November 17, 2007, 12:17:44 PM

Previous topic - Next topic

stebra

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.

Vortex

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]

Mark Jones

Hi Stebra, do you want to access this file from the DOS 16-bit land?
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Vortex

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.

MichaelW

stebra,

For information on handling files under 16-bit DOS, see Dos.inc from the older MASM macros available here.

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

eschew obfuscation

eek

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

eek

If you actually want to see whats going on then you can use this interpreter.

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