The StringCopyIf function

The StringCopyIf function copies the elements of a null-terminated string into a prepared buffer on the basis of a condition defined by a function passed through a pointer (for example, IsDigit, IsLower, IsAlpha).

Parameters: DS:AX - source string; ES:BX - destination buffer; CX - 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

An example program for the Intel 8086 assembler demonstrating the use of the StringCopyIf function for selective copying of characters from a string.

title Author: Evgeny Sergeevich Dovgopolov

.model small
.stack 100h

data segment public
    string db "He1ll3o Wo5rld!\0"
    buffer db 10 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

        lea     cx, IsDigit      ; Load the address of the IsDigit procedure into the cx register
        lea     bx, es:[buffer]  ; Load the address of the variable buffer into the es:bx register
        lea     ax, ds:[string]  ; Load the address of the variable string into the ds:ax register
        call    StringCopyIf     ; Call the StringCopyIf procedure (ds:ax, es:bx, cx)

        lea     ax, ds:[buffer]  ; Load the address of the variable buffer into the ds:ax register
        call    WriteString      ; Call the WriteString procedure (ax:buffer)

        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

135

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