FindFirstFileEx function
The FindFirstFileEx function searches for the first file matching the pattern and attributes and stores its name in a buffer. The parameters are passed through the stack. The function automatically aligns the stack to 6 bytes.
Parameters (stack): 1. Pointer to the pattern. 2. Pointer to the buffer. 3. Search attributes.
Return value: On success (CF=0) the file is found; on error (CF=1) AX contains the error code.
Flag state: The function affects all flags.
Program source code
Intel 8086 assembly program example demonstrating the use of the FindFirstFileEx function to search for the first file by pattern and attributes.
title .286C .model small .stack 100h data segment public pattern db "*.txt", 0 fmtout db "Found file: ${.s}\n\0" buffer db 13 dup(0) data ends code segment public assume ds:data, cs:code include Handyfar.inc ; Include the file with functions include Handymac.inc ; Include the file with macros main proc call SetDataSegment ; Call the SetDataSegment procedure push 0 ; 3rd: Push the search attributes onto the top of the stack pushs es:[buffer] ; 2nd: Push the address of buffer onto the top of the stack pushs ds:[pattern] ; 1st: Push the address of pattern onto the top of the stack call FindFirstFileEx ; Call the FindFirstFileEx(pattern, buffer, 0) procedure := AX and CF pushs ds:[buffer] ; Push the address of the buffer variable onto the top of the stack push BLACK ; Push the text colour value onto the top of the stack push CYAN ; Push the background colour value onto the top of the stack pushs ds:[fmtout] ; Push the address of the fmtout variable onto the top of the stack call WriteStringExD ; Call the WriteStringExD(fmtout, CYAN, BLACK, buffer) procedure add sp, 2 ; Align the stack to 2 bytes. Pop buffer from the stack push 0 ; Push the byte return code onto the top of the stack call ExitProcessEx ; Call the ExitProcessEx(0) procedure main endp code ends end main
Found file: Handyfar.txt
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".