CreateFolderEx function
The CreateFolderEx function creates a new folder. The pointer to the folder name is passed through the stack. The function automatically aligns the stack to 2 bytes.
Parameters (stack): 1. Pointer to the folder name.
Return value: On success (CF=0) the folder is created; 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 CreateFolderEx function to create a new folder. The folder name is passed through the stack.
title .286C .model small .stack 100h data segment public fName db "Assembly", 0 cSuccess db "The folder was created successfully!\0" cError db "An error occurred while creating '%s'. Error code: %d\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 pushs ds:[fName] ; Push the address of the fName variable onto the top of the stack call CreateFolderEx ; Call the CreateFolderEx(fName) procedure := AX and CF jnc @NoCreateFolderError ; If CF=0, jump to the label @NoCreateFolderError push ax ; 3rd: Push ax onto the top of the stack (error code) pushs ds:[fName] ; 2nd: Push the address of the fName variable onto the top of the stack leaax ds:[cError] ; 1st: Load the address of the cError format string into the ds:ax register call PrintFormatString ; Call the PrintFormatString(ax:cError, fName, ax) procedure add sp, 4 ; Align the stack jmp @Done ; Perform an unconditional jump to the label @Done @NoCreateFolderError: pushs ds:[cSuccess] ; Push the address of the cSuccess variable onto the top of the stack call WriteStringEx ; Call the WriteStringEx(cSuccess) procedure @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
The folder was created successfully!
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".