Back to index |
The dos interrupt contains functions which makes it easy to create, open, read, write,
close and delete files.
A file should always be closed before the program is terminated. Create file
Function 3ch creates a file. ds:dx should point to the ASCIIZ filename. cx is is the file
attribute.
mov ah,3ch
Open file
Function 3dh opens a file. ds:dx points to the ASCIIZ filename. If al is 0 then the file is
opened as read only, if al is 1 the file will be opened as write only and if al is 2 the file will
be opened as read/write.
mov ax,3d02h
Read from file
Function 3fh reads a string from a file. bx is the file handle, cx is the number of bytes you
want to read and ds:dx is where to put them.
mov ah,3fh
Write to file Function 40h writes a string to a file. bx is the file handle, cx is the number of bytes to write and ds:dx points to the string you want to write. On return cf is set if an error occurred.
mov ah,40h
Move file pointer If the file is bigger than 64kb you need to use function 42h to read the whole file. It moves the file pointer to a new location. cx is the high bits of the new location and dx is the low bits. al is where you want to move the pointer from. 0 is beginning of file, 1 is the current location and 2 is end of file. bx is the file handle. On return cf is set if an error occurred.
mov ax,4200h
Delete file Function 41h deletes a file. ds:dx points to the ASCIIZ filename. On return cf is set if an error occurred.
mov ah,41h
Close file Function 3eh closes a file. bx is the file handle. On return cf is set if an error occurred.
mov ah,3eh
In the sample program filea.com creates a file and fileb.com deletes it.
|
Jesper L. Poulsen |