The StringSpan function

The StringSpan function returns the length of the maximal initial segment of the first string that consists only of the characters found in the second string.

Parameters: DS:AX - pointer to the string to search; ES:BX - pointer to the string with the set of allowed characters.

Return value: AX - length of the segment found.

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 StringSpan function to find the length of an initial segment of allowed characters.

title Author: Evgeny Sergeevich Dovgopolov

.model small
.stack 100h

data segment public
    string db "8783274ABCDEFGH1234\0"
    search db "0123456789\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     bx, es:[search]  ; Load the address of the variable search into the es:bx register
        lea     ax, ds:[string]  ; Load the address of the variable string into the ds:ax register
        call    StringSpan       ; Call the StringSpan procedure (ds:ax, es:bx) := AX
        call    WriteString      ; Call the WriteString procedure (ax)

        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

ABCDEFGH1234

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