FindAllFilesEx function

The FindAllFilesEx function searches for all files matching the pattern and stores their names in a buffer, separating them with the 7Fh character. 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 files are 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 FindAllFilesEx function to search for all files by pattern and output them with the 7Fh separator.

title Author: Evgeny Sergeevich Dovgopolov

.286C
.model small
.stack 100h

data segment public
    pattern db "*.obj", 0
    buffer  db 128 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    FindAllFilesEx   ; Call the FindAllFilesEx(pattern, buffer, 0) procedure := AX and CF

        lea     si, ds:[buffer]  ; Load the address of the buffer variable into the source register ds:si

    PrintFilesLoop:
        lodsb                    ; Load the byte at address ds:si into the al register

        test    al, al           ; Compare al with 0
        jz      Done             ; If ZF=1, jump to the label Done

        cmp     al, 7Fh          ; Compare al with 7Fh
        je      NewLine          ; If ZF=1, jump to the label NewLine

        call    PutChar          ; Call the PrintChar(al) procedure
        jmp     PrintFilesLoop   ; Loop while ZF is not 0 or AL is not equal to 7F

    NewLine:
        call    PrintNewLine     ; Call the PrintNewLine procedure
        jmp     PrintFilesLoop   ; Jump unconditionally to the label PrintFilesLoop

    Done:
        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

HANDYFAR.OBJ
MAIN.OBJ

Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".