The FindAllFiles function
The FindAllFiles function searches for all files matching the specified name pattern and stores their names in the provided buffer. The names in the buffer are separated by the 7Fh character.
Parameters: DS:AX - pointer to the pattern string; ES:BX - pointer to the buffer; CX - the file attributes for the search.
Return value: On success (CF=0) the files are found; on error (CF=1) AX contains the error code.
Flag state: The function affects all flags.
Program source code
An example program for the Intel 8086 assembler demonstrating the use of the FindAllFiles function to find all files matching a pattern.
title .model small .stack 100h data segment public pattern db "*.txt", 0 buffer db 128 dup(0) data ends code segment public ; Start of the code segment assume ds:data, cs:code include Handyfar.inc ; Include the file with functions main proc ; Start of the main procedure call SetDataSegment ; Call the SetDataSegment procedure xor cx, cx ; Set the attribute to 0 lea bx, es:[buffer] ; Load the address of the buffer string into the es:bx register lea ax, ds:[pattern] ; Load the address of the pattern string into the ds:ax register call FindAllFiles ; Call the FindAllFiles procedure (ds:ax, es:bx, 0) := AX and CF lea si, ds:[buffer] ; Load the address of the buffer variable into the ds:si source register PrintFilesLoop: lodsb ; Load the byte at the address ds:si into the al register test al, al ; Check al for 0 jz Done ; If ZF = 1, jump to the label Done cmp al, 7Fh ; Check al for 7Fh je NewLine ; If ZF = 1, jump to the label NewLine call PutChar ; Call the PrintChar procedure (al) jmp PrintFilesLoop ; Perform an unconditional jump to the label PrintFilesLoop NewLine: call PrintNewLine ; Call the PrintNewLine procedure jmp PrintFilesLoop ; Loop while ZF is not equal to 0 or AL is not equal to 7F Done: xor al, al ; Clear the al register call ExitProcess ; Call the ExitProcess procedure main endp ; End of the main procedure code ends ; End of the code segment end main ; End of file. The main procedure is the entry point
HANDYFAR.OBJ
HANDYGFX.OBJ
MAIN.OBJ
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".