I guess im "just starting out" here, so i will post my inquiry here :) Unlike yesterdays woes with moving data between windows, today's chores are going quite smoothly. Im hacking out how to make use of file I/O (other than one big write/read as Iczelion's tut gets into). I have actually gotten it to write read no problem. But in hindsite to C's fprintf etc., masm32 provides no support that i know of for actually formatting file output and input. I could beging to write my own collection of routines, but this seems to be ANTI-RAD and i know im not the first to venture here, so i thought i would ask if anyone has or knows where i can find basic routines to do read/write operations. Thanx Again NaN
Posted on 2001-02-21 13:50:00 by NaN
Hello, the folowing is taken from : A introduction to x86 assembly Written by Gavin Estey email:gavin@senator.demon.co.uk This document is version: 0.9 Beta 2/19/95 and may help you ;) -------- Files and how to used them: Files can be opened, read and written to. DOS has some ways of doing this which save us the trouble of writing our own routines. Yes, more interrupts. Here is a list of helpful functions of interrupt 21h that we are going to need to use for our simple file viewer. Function 3Dh: open file Opens an existing file for reading, writing or appending on the specified drive and filename. INPUT: AH = 3Dh AL = access mode bits 0-2 000 = read only 001 = write only 010 = read/write bits 4-6 Sharing mode (DOS 3+) 000 = compatibility mode 001 = deny all (only current program can access file) 010 = deny write (other programs can only read it) 011 = deny read (other programs can only write to it) 100 = deny none DS:DX = segment:offset of ASCIIZ pathname OUTPUT: CF = 0 function is succesful AX = handle CF = 1 error has occured AX = error code 01h missing file sharing software 02h file not found 03h path not found or file does not exist 04h no handle available 05h access denied 0Ch access mode not permitted What does ASCIIZ mean? An ASCIIZ string is a ASCII string with a zero on the end (instead of a dollar sign). Important: Remember to save the file handle it is needed for later. How to save the file handle: It is important to save the file handle because this is needed to do anything with the file. Well how is this done? There are two methods, which is better? Copy the file handle into another register and don't use that register. Copy it to a variable in memory. The disadvantages with the first method is that you will have to remember not to use the register you saved it in and it wastes a register that can be used for something more useful. We are going to use the second. This is how it is done: FileHandle DW 0 ;use this for saving the file ;handle MOV FileHandle,ax ;save the file handle (same as ;FileHandle=ax) Function 3Eh: close file Closes a file that has been opened. INPUT: AX = 3Eh BX = file handle OUTPUT: CF = 0 function is sucsessful AX = destroyed CF = 1 function not sucsessful AX = error code - 06h file not opened or unautorized handle. Important: Don't call this function with a zero handle because that will close the standard input (the keyboard) and you won't be able to enter anything. Function 3Fh: read file/device Reads bytes from a file or device to a buffer. INPUT: AH = 3Fh BX = handle CX = number of bytes to be read DS:DX = segment:offset of a buffer OUTPUT: CF = 0 function is successful AX = number of bytes read CF = 1 an error has occured 05h access denied 06h illegal handle or file not opened If CF = 0 and AX = 0 then the file pointer was already at the end of the file and no more can be read. If CF = 0 and AX is smaller than CX then only part was read because the end of the file was reached or an error occured. This function can also be used to get input from the keyboard. Use a handle of 0, and it stops reading after the first carriage return, or once a specified number of characters have been read. This is a good and easy method to use to only let the user enter a certain amount of characters. Note: If you are using A86 this will cause an error. Change @data to data to make it work. .MODEL smal
Posted on 2001-02-21 15:08:00 by WH¥
NaN, Don't be afraid to be "anti-RAD", it will improve your code by writing what works for you. File IO is no real joy to standardise as the range of applications for it are very large. You can do all of the file IO functions in Windows, Open, Read, Write, set file pointers etc... Depending on what you are doing, there are advantages in reading large blocks into memory and processing it there, disk thrashing on small amounts of data is very slow. WH¥, You can forget the old DOS junk, it does not work in 32 bit code as the interrupts are not available in protected mode. The other factor is that the API calls in native 32 bit mode will eat them alive in performance terms. Regards, hutch@pbq.com.au
Posted on 2001-02-21 16:47:00 by hutch--
Thanx Hutch-- and WHY, Somehow I new I would have to write them on my own, but I would have been more upset to learn that after I wrote them, a simular set was sitting at http://www.Doh!.com :) NaN This message was edited by NaN, on 2/21/2001 5:16:52 PM
Posted on 2001-02-21 17:16:00 by NaN
Doh !!!
Posted on 2001-02-21 18:32:00 by Ernie
If you need formatted output like C's printf...you can use sprintf to format the string in memory, and use the usual :) api function to write to a file. As far as I remember, kernel32 has an sprintf replacement, as long as you don't need floatingpoint. Writing an sprintf replacement is not very hard as long as you don't have to do float.
Posted on 2001-02-22 02:47:00 by f0dder
Thanx for the tip, but I can't seem to find it in the MASM32. I checked the kernel32.inc for a proto as well as user32.inc and the MSDN. NaN
Posted on 2001-02-22 11:22:00 by NaN
NaN, sprintf has had a w put in front of it for some weird reason, I can't remember which .inc it's in as I don't have them to hand at the moment (computer re-installs and all that jazz). So have a look for "wsprintf". umbongo
Posted on 2001-02-22 15:15:00 by umbongo
ah, here it is, look in \masm32\m32lib\dwtoa.asm it's in there :grin: umbongo
Posted on 2001-02-22 15:19:00 by umbongo
I dunno about dwtoa.asm (???) but i did find what you were talking about :) Thank you, im glad I go side tracked with DLL's before i started hacking out routines... BTW: its proto is in Windows.inc NaN
Posted on 2001-02-22 22:54:00 by NaN