The StringStartsWith function
The StringStartsWith function checks whether the first string starts with the specified second substring.
Parameters: DS:AX - pointer to the first string; ES:BX - pointer to the second string (substring).
Return value: ZF = 1 if the first string starts with the substring; ZF = 0 otherwise.
Flag state: The function affects all flags.
Program source code
An example program for the Intel 8086 assembler demonstrating the use of the StringStartsWith function to check the beginning of a string.
title .model small .stack 100h data segment public string db "Evgeny Dovgopolov\0" mName db "Evge\0" true_msg db "String '%s' starts with '%s'\0" false_msg db "String '%s' does not start with '%s'\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:[mName] ; Load the address of the variable mName into the es:bx register lea ax, ds:[string] ; Load the address of the variable string into the ds:ax register call StringStartsWith ; Call the StringStartsWith procedure (ds:ax, es:bx) jne False ; If ZF=0, jump to the False label True: lea ax, ds:[mName] ; Load the address of the variable mName into the ds:ax register push ax ; 3rd: Save the ax register value on the stack lea ax, ds:[string] ; Load the address of the variable string into the ds:ax register push ax ; 2nd: save the ax register value on the stack lea ax, ds:[true_msg] ; 1st: Load the address of the true_msg format string into the ds:ax register jmp Done ; Jump unconditionally to the Done label False: lea ax, ds:[mName] ; Load the address of the variable mName into the ds:ax register push ax ; 3rd: Save the ax register value on the stack lea ax, ds:[string] ; Load the address of the variable string into the ds:ax register push ax ; 2nd: save the ax register value on the stack lea ax, ds:[false_msg] ; 1st: Load the address of the false_msg format string into the ds:ax register Done: call PrintFormatString ; Call the PrintFormatString procedure (ax) add sp, 4 ; Align the stack 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
String 'Evgeny Dovgopolov' starts with 'Evge'
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".