guys?is it even possible that once i created a file already with my program then execute that program again wont create a file anymore?.. like q.txt then its created..but when i execute my program again and type a string to create a file like w.txt..it doesnt create the file..theres a screenshot of what ive done with my sample codes..it kept bugging making me crazy to figure out whats wrong..
heres my code if there is something wrong please help me:

.model small
.stack 100h
.data
buff db 10,?,10 dup(' ')
handle dw ?
.code
start:
mov ax,seg buff
mov ds,ax
mov dx,offset buff
mov ah,0ah                    ; string input
int 21h
push ax                          ; string placed to stack
je print
		print:
		xor bx, bx
		mov bl, buff[1]
		mov buff[bx+2], '$'
		mov dx, offset buff + 2
		mov ah, 9
		int 21h
mov ah,3ch                    ; create file attribute
mov cx,0                        ; normal attribute
pop bx                           ; get data from stack
mov ah,3ch                    ; create file with file name from stack
int 21h
mov handle,ax
finish:
mov ah,4ch                    ; terminate program
int 21h
end start

Recommended Answers

All 7 Replies

AH=3Ch takes an ASCIZ null terminated file name
pointed to by DS : DX
same for AH=5Bh but 5Bh will not create the file if it already
exists.
Besides this all the other parameters are correct,
you just need to pass it the address of
a null-terminated instead of a '$'-terminated string in DS : DX.

well i use push pop...so that it will easy for string to be retrieve later on..
i was just wondering how come my program works and sometimes doesnt work..thats whats been bugging me all week..my defense is tom..and my program is kinda working..that code above was part of my program..hope everything goes smooth tom..thanks anyway..

I'm sorry if your frustrated, I also notice this:

mov ax,seg buff
mov ds,ax
mov dx,offset buff
mov ah,0ah ; string input
int 21h
push ax ; AH=0Ah AL=last char read
             ; how is this your string???

And this:

mov ah,3ch
mov cx,0
pop bx   ; 3Ch has no parameter for BX
mov ah,3ch
int 21h

i knw thats one of my problem..but my program as its suppose to be..ive even use an disassembler with my last working program and has no issues regarding not working..the code was really same as the code ive used..anyway thnks for evrything..i jst passed my defense earlier..now ill try to learn asm..wanting be an asm dev someday...which assembler do u guys prefer tasm?masm?nasm?or fasm?

I have modified your code, and discovered the problem
really was that the string wasn't null-terminated,
this code works:

bits 16
org 100h

start:
mov dx, buf
mov ah, 0xa
int 0x21

call print

xor bh, bh
mov bl, [buf+1]
mov byte [buf+2+bx], 0x0 ; Null terminate string
mov dx, buf+2
mov cx, 0
mov ah, 0x3c
int 0x21

mov [fhandle], ax

mov ax, 0x4c00
int 0x21

buf db 0x10, 0
    times 0x10 db 0
fhandle dw 0

print:
 xor bh, bh
 mov bl, [buf+1]
 mov byte [buf+2+bx], 0x24
 mov dx, buf+2
 mov ah, 0x9
 int 0x21
 ret

And this code doesn't work:

bits 16
org 100h

start:
mov dx, buf
mov ah, 0xa
int 0x21

call print

xor bh, bh
mov bl, [buf+1]
mov byte [buf+2+bx], 0x24 ; NOT NULL-TERMINATED
mov dx, buf+2
mov cx, 0
mov ah, 0x3c
int 0x21

mov [fhandle], ax

mov ax, 0x4c00
int 0x21

buf db 0x10, 0
    times 0x10 db 0
fhandle dw 0

print:
 xor bh, bh
 mov bl, [buf+1]
 mov byte [buf+2+bx], 0x24
 mov dx, buf+2
 mov ah, 0x9
 int 0x21
 ret

We want you to learn, and good luck!

MZ

thnks man..,ya i really want to learn asm and be an aspiring asm dev some day..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.