FindSubStringEx function
The FindSubStringEx function searches for the first occurrence of a substring in a string. The pointers to the string and the substring are passed through the stack. It returns a pointer to the substring (CF=0) or 8000h (CF=1). The function automatically aligns the stack to 4 bytes.
Parameters (stack): 1. Pointer to the string. 2. Pointer to the substring.
Return value: AX: pointer (CF=0) or 8000h (CF=1).
Flag state: The function affects the CF flag.
Program source code (Example 1)
Intel 8086 assembly program example demonstrating the use of the FindSubStringEx function to search for a substring and print it to the console.
title .286C .model small .stack 100h data segment public string db "Hello, my world!\0" substr db "my\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:[substr] ; Push the address of the substr variable onto the top of the stack pushs ds:[string] ; Push the address of the string variable onto the top of the stack call FindSubStringEx ; Call the FindSubStringEx(string, substr) procedure push ax ; Push the value of the ax register onto the top of the stack call WriteStringEx ; Call the WriteStringEx(value from the stack) procedure 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
my world!
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".
Program source code (Example 2)
Intel 8086 assembly program example demonstrating the use of the FindSubStringEx function to search for a substring and print all occurrences in a loop.
title .286C .model small .stack 100h data segment public string db "Hello, my world, my paradise!\0" substr db "my\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:[substr] ; Push the address of the substr variable onto the top of the stack pushs ds:[string] ; Push the address of the string variable onto the top of the stack MainLoop: call FindSubStringEx ; Call the FindSubStringEx(string, substr) procedure jc Done ; If CF=1, jump to the label Done call WriteString ; Call the WriteString(ax) procedure call PrintNewLine ; Call the PrintNewLine procedure jmp MainLoop ; Jump unconditionally to the label MainLoop 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
my world, my paradise!
my paradise!
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".