Untitled Document
DOS: Our own DOS “dir” (Find Files)
Author: InternetNightmare
Hello again. This is first tutorial in DOS series. Here I’ll show you how to write your own dir function. Not very useful, but should give you some DOS knowledge. First thing we need to do is change DTA (Disk Transfer Area) table place. By default it’s mapped at address 0x80 in program segment, but it’s not very good, because it’s the same place were command line is stored.
mov ah, 0x1A
mov dx, DTA
int 21h
Simple, DX stores pointer to new DTA table. How does that DTA thing look like? Like that:
Offset |
Size |
Meaning |
0 |
23 bytes |
Data that only DOS needs |
0x15 |
Byte |
File attribute |
0x16 |
Word |
File creation/modification time |
0x18 |
Word |
File creation/modification date |
0x1A |
Word |
File size |
0x1C |
Word |
Unknown… |
0x1E |
13 Bytes |
File name terminated with zero |
Now, we have our table set up, we can find the first file.
mov ah, 0x4E
mov dx, query
int 21h
It’s pretty simple. DX stores pointer to search query (DOS dir argument) terminated with zero. Like:
db “*.*”, 0x0
db “*.com”, 0x0
Carry flag is set if file wasn’t found. If file was found DTA table is filled with files attributes. For all other files we want to find we use other call:
mov ah, 0x4F
mov dx, query
int 21h
If no more files found Carry Flag is set after the call, if file is found DTA table is filled with it’s attributes. That’s it. Grab the source to see how everything looks. Have fun!
NASM Source code - here
|