(This tutorial was originally written in 2004 and featured in http://asm.inightmare.org/)
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:
|0||23 bytes||Data that only DOS needs|
|0x16||Word||File creation/modification time|
|0x18||Word||File creation/modification date|
|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