flat assembler
Message board for the users of flat assembler.

flat assembler > DOS > can't write file?

Author
Thread Post new topic Reply to topic
kty11



Joined: 30 Dec 2012
Posts: 21
Location: south korea
hello
I wonder why I can't write a file with following code.
I use win7 32bit and the .com file ran on dosbox(I also try on win7 too, by double clicking it)

the code is here
Code:
org 100h

        call open_new_file
        mov ah, 40h;write
        mov bx, [new_file_handle]
        mov cx,2;write 2 bytes
        mov dx, temp
        int 21h

        mov ah, 3eh;close file
        mov bx, [new_file_handle]
        int 21h

        mov ah, 00
        int 16h;wait key

        mov ax, 4c00h
        int 21h;exit

open_new_file:
        push bp
        mov bp, sp
        mov ah, 3dh;open file
        mov al, 02h;write only
        mov dx, new_file_name ;out.kty
        int 21h
        mov [new_file_handle], ax
        leave
        ret


temp:
        dw 0xffaa

new_file_handle:
        dw 0
new_file_name:
        db "out.bin", 0
    


welcome any helps
thanks

_________________
since 1990 November 4th
Post 10 Jan 2013, 23:34
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1251
Location: Underwater
INT 21h / AH= 3Dh opens an existing file so you have to create it first.
Post 11 Jan 2013, 06:50
View user's profile Send private message Reply with quote
kty11



Joined: 30 Dec 2012
Posts: 21
Location: south korea
Picnic wrote:
INT 21h / AH= 3Dh opens an existing file so you have to create it first.

I got it thanks!

_________________
since 1990 November 4th
Post 11 Jan 2013, 06:51
View user's profile Send private message Reply with quote
freecrac



Joined: 19 Oct 2011
Posts: 117
Location: Germany Hamburg
kty11 wrote:
Picnic wrote:
INT 21h / AH= 3Dh opens an existing file so you have to create it first.

I got it thanks!

RBIL->inter61b.zip->INTERRUP.F
Code:
--------D-213C-------------------------------
INT 21 - DOS 2+ - "CREAT" - CREATE OR TRUNCATE FILE
        AH = 3Ch
        CX = file attributes (see #01401)
        DS:DX -> ASCIZ filename
Return: CF clear if successful
            AX = file handle
        CF set on error
            AX = error code (03h,04h,05h) (see #01680 at AH=59h/BX=0000h)
Notes:  if a file with the given name exists, it is truncated to zero length
        under the FlashTek X-32 DOS extender, the pointer is in DS:EDX
        DR DOS checks the system password or explicitly supplied password at
          the end of the filename against the reserved field in the directory
          entry before allowing access
SeeAlso: AH=16h,AH=3Dh,AH=5Ah,AH=5Bh,AH=93h,INT 2F/AX=1117h

Bitfields for file attributes:
Bit(s)  Description     (Table 01401)
 0      read-only
 1      hidden
 2      system
 3      volume label (ignored)
 4      reserved, must be zero (directory)
 5      archive bit
 7      if set, file is shareable under Novell NetWare
    

Dirk
Post 11 Jan 2013, 08:12
View user's profile Send private message Send e-mail Reply with quote
ACP



Joined: 23 Sep 2006
Posts: 198
Two more tips:

- always check for error before proceeding and processing return data further as you migth work with invalid file handle for example. Int 21h file functions tend to use Carry Flag (CF) to inform you there is something wrong with your call.

- Win7 does not support DOS COM files - this support is long gone from modern Windows system so DosBox or virtual machines like VMWare with DOS or FreeDOS installed are the only way to go

Hopes it will help you.
Post 11 Jan 2013, 12:35
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1388
Location: Toronto, Canada
I am using DOSBOX to debug some code for 320x200x256.
Really cool program that DOSBOX!
Post 11 Jan 2013, 13:22
View user's profile Send private message Send e-mail Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
AsmGuru62,

Bochs has debugger included, you may like it too.
Post 11 Jan 2013, 21:48
View user's profile Send private message 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-2018, Tomasz Grysztar.

Powered by rwasa.