flat assembler
Message board for the users of flat assembler.

Index > DOS > 16 Bit DOS INT's in windows vista.

Author
Thread Post new topic Reply to topic
Walkerboh



Joined: 08 Jul 2010
Posts: 17
Walkerboh 08 Jul 2010, 20:57
I'm learning assembly from the ground up(16 bit) on Vista, and I'm working on creating/opening/reading/writing files with DOS Interrupts. File creation,writing and opening is not working for me. Reading works fine!

Does the 16 bit FASM code, just not work right with vista? I am running my code from an administrator account.

Here are some code snippets in case I'm just writing my program incorrectly.

OPEN FILE SNIPPET-This code when run, puts 1 in CF
MOV ah,0x3D
MOV al,2
MOV dx,FilePath
INT 21h
JC OpenErrorh
MOV [Handle],ax

WRITE FILE SNIPPET-This code returns no error in CF none the less it doesn't work
MOV ah,0x40
MOV bx,[Handle]
MOV cx,[ActualFileSize]
MOV dx,FileData
INT 21h
JC WriteErrorH
Post 08 Jul 2010, 20:57
View user's profile Send private message Reply with quote
Goplat



Joined: 15 Sep 2006
Posts: 181
Goplat 08 Jul 2010, 21:49
DOS call 3D is only for opening an existing file, it won't create new files.
Post 08 Jul 2010, 21:49
View user's profile Send private message Reply with quote
Walkerboh



Joined: 08 Jul 2010
Posts: 17
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!','$'
    
[/code]
Post 08 Jul 2010, 23:16
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 789
Location: Adelaide
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?
Post 09 Jul 2010, 00:53
View user's profile Send private message Reply with quote
Walkerboh



Joined: 08 Jul 2010
Posts: 17
Walkerboh 09 Jul 2010, 01:00
Aye, however, even with the INT 21h it doesn't create the file data1.txt in C:\
Post 09 Jul 2010, 01:00
View user's profile Send private message Reply with quote
Walkerboh



Joined: 08 Jul 2010
Posts: 17
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

    
Post 09 Jul 2010, 01:24
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.