StringCopyIfNotEx function

The StringCopyIfNotEx function copies characters from the source string into the destination buffer if they do NOT satisfy the condition specified by a function. The function automatically aligns the stack to 6 bytes.

Parameters (stack): 1. Pointer to the source string. 2. Pointer to the buffer. 3. Pointer to the condition function.

Return value: The function does not return a value.

Flag state: The function does not modify the flags.

Program source code

Intel 8086 assembly program example demonstrating the use of the StringCopyIfNotEx function to copy characters that do NOT satisfy a condition.

title Author: Evgeny Sergeevich Dovgopolov

.286C
.model small
.stack 100h

data segment public
    string db "He1ll3o Wo5rld!\0"
    buffer db 20 dup(0)
    fmtout db "Copied elements: [%s].\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   IsDigit            ; 3rd: Push the address of function IsDigit onto the stack
        pushs   es:[buffer]        ; 2nd: Push the address of variable buffer onto the stack
        pushs   ds:[string]        ; 1st: Push the address of variable string onto the stack
        call    StringCopyIfNotEx  ; Call procedure StringCopyIfNotEx(string, buffer, IsDigit)

        pushs   ds:[buffer]        ; 2nd: Push the address of variable buffer onto the stack
        leaax   ds:[fmtout]        ; 1st: Load the address of format string fmtout into register ds:ax
        call    PrintFormatString  ; Call procedure PrintFormatString(ax:fmtout, buffer)
        add     sp, 2              ; Align 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

Copied elements: [Hello World!].

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