Creating a file in asm
I''m trying to create a new file in asm, but the error sub keeps getting tripped. I can''t figure out why. I''m sure its something really dumb. Any help is appreciated.
DOSSEG
.MODEL SMALl
.STACK 200h
.DATA
filename db "c:\tasm\texture.grp$"
handle dw 0
filemessage db "Error.$"
fileheader db "SG-texture"
tname db [9]
.CODE
START:
mov AH,3ch ;create the file
mov CL,0
mov DX,seg filename
mov DS,DX
mov DX,offset filename
int 21h
mov handle,AX
jnc cont3
call fileerror
cont3:
mov AH,40h ;write file header
mov BX,handle
mov CX,10
mov DX,seg fileheader
mov DS,DX
mov DX,offset fileheader
cmp AX,10
jz cont1
call fileerror
cont1:
mov BX,0 ;get a texture name
getname:
mov AH,0 ;get a keypress
int 16h
cmp AH,28 ;check for enter
jz finishedgetname
cmp AH,0 ;check for no character
jz getname
push AX ;print the character
mov DL,AL
mov AH,2
int 21h
pop AX
cmp AH,14 ;check for backspace
jnz contgetname
dec BX
jmp getname
contgetname:
inc BX ;add the keypress to the name
cmp BX,10
jz finishedgetname
mov tname[BX],AL
jmp getname
finishedgetname:
mov AH,40h ;write the texture name
mov BX,handle
mov CX,10
mov DX,seg tname[0]
mov DS,DX
mov DX,offset tname[0]
int 21h
cmp AX,10
jz cont2
call fileerror
cont2:
endprog:
mov AH,3eh ;close the file
mov BX,handle
int 21h
mov AX,0003h ;end prog
int 10h
mov AX,4c00h
int 21h
Proc fileerror ;Dislay an error
mov AX,seg filemessage ;display file error message
mov DS,AX
mov DX,offset filemessage
mov AH,9
int 21h
mov AX,0 ;wait for keypress
int 16h
jmp endprog ;end the program
endp fileerror
END START
Look! There! Up in the sky! It''s Birdman! Da-du-du-daaaaah!
NO! Those source tags didn''t work! I put in:
"" without the "s of course
blah blah
" and it didn''t do it!
Look! There! Up in the sky! It''s Birdman! Da-du-du-daaaaah!
"" without the "s of course
blah blah
" and it didn''t do it!
Look! There! Up in the sky! It''s Birdman! Da-du-du-daaaaah!
HEY! It took the source statements out of the post! Even though they were in ""s.
Okay, this is what I did:
(source) except I used <> brackets
blah blah blah
(/source)
Okay, this is what I did:
(source) except I used <> brackets
blah blah blah
(/source)
Use square brackets, duh.
[ source ] [ /source ] (minus the spaces).
I don''t know ASM well, so I can''t help you with that problem.
[ source ] [ /source ] (minus the spaces).
I don''t know ASM well, so I can''t help you with that problem.
ooops! I guess I get the dummy award today!
Look! There! Up in the sky! It''s Birdman! Da-du-du-daaaaah!
Look! There! Up in the sky! It''s Birdman! Da-du-du-daaaaah!
I would reccomend editing your first post to make your code much more readable... heh.
-----------------------------
Valkyrias: Tears of Valkyries
-----------------------------
Valkyrias: Tears of Valkyries
I know barely any asm, but if it isn''t a hassle, you could create seperate error routines for each section it is possible to call it in, that way you narrow down where the error is occuring.
First, Mauling Monkey: I know where the error is occuring. It happens on the create statement. I just disabled the other error calls and narrowed it down.
Second, heres the code in a more readable format:
By the way: this is for TASM 3.1
DOSSEG .MODEL SMALl.STACK 200h.DATA filename db "c:\tasm\texture.grp$" handle dw 0 filemessage db "Error.$" fileheader db "SG-texture" tname db [9].CODESTART: mov AH,3ch ;create the file mov CL,0 mov DX,seg filename mov DS,DX mov DX,offset filename int 21h mov handle,AX jnc cont3 call fileerror cont3: mov AH,40h ;write file header mov BX,handle mov CX,10 mov DX,seg fileheader mov DS,DX mov DX,offset fileheader cmp AX,10 jz cont1 call fileerror cont1: mov BX,0 ;get a texture name getname: mov AH,0 ;get a keypress int 16h cmp AH,28 ;check for enter jz finishedgetname cmp AH,0 ;check for no character jz getname push AX ;print the character mov DL,AL mov AH,2 int 21h pop AX cmp AH,14 ;check for backspace jnz contgetname dec BX jmp getname contgetname: inc BX ;add the keypress to the name cmp BX,10 jz finishedgetname mov tname[BX],AL jmp getname finishedgetname: mov AH,40h ;write the texture name mov BX,handle mov CX,10 mov DX,seg tname[0] mov DS,DX mov DX,offset tname[0] int 21h cmp AX,10 jz cont2 call fileerror cont2: endprog: mov AH,3eh ;close the file mov BX,handle int 21h mov AX,0003h ;end prog int 10h mov AX,4c00h int 21hProc fileerror ;Dislay an error mov AX,seg filemessage ;display file error message mov DS,AX mov DX,offset filemessage mov AH,9 int 21h mov AX,0 ;wait for keypress int 16h jmp endprog ;end the programendp fileerrorEND START
Please help! Again, I''m sure its somehting stupid, but I can''t find it.
Look! There! Up in the sky! It''s Birdman! Da-du-du-daaaaah!
mov AH,3ch ;create the filemov CL,0 mov DX,seg filenamemov DS,DXmov DX,offset filenameint 21hmov handle,AXjnc cont3
I assume you mean that section of code as your "create statement". According to my handy dandy assembly programmer''s guide, neither
mov
nor int
instructions alter the carry flag, which is what jnc
(Jump if No Carry) checks. So if you don''t alter the flag, I don''t know how you can check if the file was created successfully.But again, if you say that the rest of your code is fine, I could be wrong.
Hmm, really? I always though that int did something, depending on the call that could change the carry flag. According to a tutorial I have with open/close/create file stuff in it, that should work. If the carry is set, then AX tells the file error. But it could be wrong. But I know something is amiss, because later in the program I try to write to the file, but it always has a size of 0 bytes, no matter what I do.
Look! There! Up in the sky! It''s Birdman! Da-du-du-daaaaah!
Look! There! Up in the sky! It''s Birdman! Da-du-du-daaaaah!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement