Re: create a file



Utilisateur1 wrote:

You know what? You've got a problem even before the one
we've already identified...

> mov ax,3d01h ; open file

This opens an *existing* file. If "FIL.TXT" doesn't already
exist, this will fail with error 2. Look into subfunction
3Ch - create file (set cx to the "attributes" you want). You
*don't* want to use this on an existing file if you want to
keep its contents and write more to it! In that case, you'll
want to use subfunction 3Dh, as you've got, followed by
subfunction 42h...

mov ax, 4202h ; seek to end of file
mov bx, handle ; or "dword ptr handle", *not* "offset
handle"!
xor cx, cx ; no offset from EOF
xor dx, dx
int 21h
jc erreur

.... *now* you can write new data to the file.

> mov dx, offset fildat
> int 21h
> jb erreur ; error in french

Since you seem to be able to print a number, you might want
to display the error code before quitting. It might help you
figure out what's going wrong.

> mov offset handle,ax
> mov ax,4200h
> mov bx, offset handle

Here's the problem...

> xor cx,cx ; begin byte 0
> mov dx,0001 ; 1st byte modified is the second
> int 21h
> jb erreur

.... and if you print out the error number, it'll be "invalid
handle" (once you get this far), I'll bet. I'm not sure what
you intend to do here. Skip over just one byte???

> mov ah,40h ; write file
> mov bx,offset handle
> mov cx,20h ; write 32 bytes
> mov dx,offset week
> int 21h
> jb erreur

Again, if you get to this point and fail, you might want to
see what the error number was...

....
> fildat db: "FIL.TXT",0 ; save date ant time
> handle db: ,0,0

There may be another "syntax issue" here... as I recall, in
"Intel syntax":

handle dw 0

is different from:

handle: dw 0

The second is a "label", and not a "variable"... "mov bx,
handle" may be treated as "offset handle" anyway. I don't
know what a86 makes of "handle dw: 0" (or "handle db: ,0,0")
- and I'm not gonna boot up dos and run a86 to find out! But
I suspect that removing all the ":"s from the data
declarations may help... although it may cause a86 to
complain about "mov offset xxx, ax", etc. (as it should!).

I hope the yakkin' about "syntax" doesn't distract you from
the "main point" - the difference between an address, and
the value that resides at that address. One you've figured
out which you want, figuring out what syntax you need to get
what you want - whether it's "offset" or "#" or "word ptr"
or "W" (a86) or nothing - should be the "easy part"...
relatively speaking...

Best,
Frank
.



Relevant Pages

  • Using IDA Pro v4.3
    ... IDA Pro claiming that you cannot easily create source files that can be ... mov(99, ecx); ... offset32 equ ... lea eax, ds:4002198h; case 0x1 ...
    (alt.lang.asm)
  • Re: Bitmap palette
    ... offset filename;offset of file in dx ... > mov dx, offset buffer;set buffer to receive palette ...
    (comp.lang.asm.x86)
  • Re: Algorithm Help
    ... hope someone can help me with an algorithm. ... offset you data bitwise from the beginning of the ... mov ebx NumberOfBytesInTable - 1 ... > to the bitmap and want to scan the bitmap until PageCount of free bits is ...
    (alt.lang.asm)
  • Re: maybe a bit OT: EEPROMs and PCs
    ... The "offset" keyword applies to variable names. ... the instruction "mov eax,abc" if you know how abc was defined? ... > "content of register" as opposed to what??? ... Register address space and memory address space are two distinct ...
    (alt.lang.asm)
  • Gnu Assembler - Real Mode - accessing variable from code
    ... I'd like to be able to locate the GDT anywhere within the ... mov esi, offset gdt_init;grabs the offset relative to wherever gdt ... of a variable - and have the preprocessor stuff this into my mov into ...
    (comp.lang.asm.x86)