StringSpanEx function

The StringSpanEx function returns the length of the longest initial span of the first string that consists only of characters found in the second string. The string pointers are passed through the stack. The function automatically aligns the stack to 4 bytes.

Parameters (stack): 1. Pointer to the string to search. 2. Pointer to the string with the set of allowed characters.

Return value: AX — the length of the found span.

Flag state: The function does not modify the flags.

Program source code

Intel 8086 assembly program example demonstrating the use of the StringSpanEx function to find the length of the initial span of allowed characters.

title Author: Evgeny Sergeevich Dovgopolov

.286C
.model small
.stack 100h

data segment public
    string db "8783274ABCDEFGH1234\0"
    search db "0123456789\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   es:[search]     ; 2nd: Push the address of variable search onto the stack
        pushs   ds:[string]     ; 1st: Push the address of variable string onto the stack
        call    StringSpanEx    ; Call procedure StringSpanEx(string, search)

        push    ax              ; Push the ax register value onto the stack
        call    WriteStringEx   ; Call procedure WriteStringEx(ax)

        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

ABCDEFGH1234

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