flat assembler
Message board for the users of flat assembler.
Index
> DOS > 16 Bit DOS INT's in windows vista. |
Author |
|
Goplat 08 Jul 2010, 21:49
DOS call 3D is only for opening an existing file, it won't create new files.
|
|||
08 Jul 2010, 21:49 |
|
Walkerboh 08 Jul 2010, 23:16
I'm not trying to create a file with DOS function 3D, for brevity's sake I just included code snippets of how I was attempting to open and write to a file.
Here is the actual program. It compiles and at runtime it APPEARS to do what I want it to do(1. Accept string from user 2. Write string to a file 3. Read file 4.Display data read from file to screen). For some reason though it accepts and prints TWO strings, and when I go to C:\ to look for C:\data1.txt in explorer..it isn't there. Is the program perhaps writing to a file invisible to windows explorer? Code: ORG 100h USE16 MaxFileSize = 256 UserInput: XOR bx,bx ;place 0 in bx STD_INPUT_HANDLE MOV ah,0x3F ;READ Function MOV dx,FileData ;buffer for input MOV cx,MaxFileSize ;Max # of bytes to accept INT 21h ;Call DOS dispatcher JC ReadErrorH ;IF CF=1 jump to ReadErrorH TEST ax,ax ;ax=0 if EOF JZ EndProgram ;IF EOF EndProgram MOV [ActualFileSize],ax ;Place # of bytes read into dw ActualFileSize CreateFile: MOV ah,0x3C ;Create File Function Code MOV dx,FilePath ;Place offset of FilePath into dx JC CreateErrorH ;IF cf=1 jmp to CreateErrorH MOV [Handle],ax ;Place handle into DW variable Handle OpenFile1: MOV ah,0x3D ;Open Function Code MOV al,2h ;Read/Write Access mode MOV dx,FilePath ;Move FilePath address to dx INT 21h ;Call DOS dispatcher ; JC OpenErrorH ;IF cf=1 jmp to OpenErrorH MOV [Handle],ax WriteFile: MOV ah,0x40 ;Write Function Code MOV bx,[Handle] ;Place file handle in bx MOV cx,[ActualFileSize] ;# of bytes to write MOV dx,FileData ;Place address of buffer into dx INT 21h ;Call DOS Dispatcher JC WriteErrorH ;If cf=1 jmp WriteErrorH ;CloseFile1: ; MOV ah,0x3E ;Close Function Code ; MOV bx,[Handle] ;Place file handle into bx ; JC CloseErrorH ;If cf=1 jmp CLoseErrorH ;OpenFile2: ; MOV ah,0x3D ; MOV al,2 ; MOV dx,FilePath ; INT 21h ; JC OpenErrorH2 ; MOV [Handle],ax ReadFile: MOV ah,0x3F MOV bx,[Handle] MOV cx,MaxFileSize MOV dx,FileData2 INT 21h JC ReadErrorH MOV [ActualFileSize],ax StringTerminate: MOV di,[ActualFileSize] ;Place # of bytes to read into di ADD di,FileData2 ;di = Actual File Size + File Data MOV al,'$' ;place $ at end of the string STOSB DisplayFile: MOV ah,09h MOV dx,FileData2 INT 21h EndProgram: MOV ah,4ch INT 21h WriteErrorH: MOV ah,09h MOV dx,WriteErrorS INT 21h JMP EndProgram ReadErrorH: MOV ah,09h MOV dx,ReadErrorS INT 21h JMP EndProgram OpenErrorH: MOV ah,09h MOV dx,OpenErrorS INT 21h JMP EndProgram CloseErrorH: MOV ah,09h MOV dx,CloseErrorS INT 21h JMP EndProgram OpenErrorH2: MOV ah,09h MOV dx,OpenErrorS2 INT 21h JMP EndProgram ReadErrorH2: MOV ah,09h MOV dx,ReadErrorS2 INT 21h JMP EndProgram CreateErrorH: MOV ah,09h MOV dx,CreateErrorS INT 21h JMP EndProgram ;DEFINITIONS FilePath db 'C:\data1.txt',0 Handle dw ? ActualFileSize dw ? FileData db MaxFileSize+1 dup (?) FileData2 db MaxFileSize+1 dup (?) WriteErrorS db 'Error writing to file!','$' ReadErrorS db 'Error reading file!','$' ReadErrorS2 db 'Error reading file2!','$' OpenErrorS db 'Error opening file!','$' OpenErrorS2 db 'Error opening file2!','$' CloseErrorS db 'Error closing file!','$' CreateErrorS db 'Error creating file!','$' |
|||
08 Jul 2010, 23:16 |
|
sinsi 09 Jul 2010, 00:53
Code: CreateFile: MOV ah,0x3C ;Create File Function Code MOV dx,FilePath ;Place offset of FilePath into dx JC CreateErrorH ;IF cf=1 jmp to CreateErrorH MOV [Handle],ax ;Place handle into DW variable Handle Missing an INT 21h isn't it? |
|||
09 Jul 2010, 00:53 |
|
Walkerboh 09 Jul 2010, 01:00
Aye, however, even with the INT 21h it doesn't create the file data1.txt in C:\
|
|||
09 Jul 2010, 01:00 |
|
Walkerboh 09 Jul 2010, 01:24
Well I found the problem with the create file code, I didn't realize you HAD to specify a file attribute >< As soon as I XOR cx,cx the file was created. Thx all
Code: MOV ah,3ch MOV dx,FilePath XOR cx,cx INT 21h JC CreateErrorH |
|||
09 Jul 2010, 01:24 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.