StringEndsWithEx function
The StringEndsWithEx function checks whether the first string ends with a given substring. Pointers to the strings are passed through the stack. The function automatically aligns the stack to 4 bytes.
Parameters (stack): 1. Pointer to the first string. 2. Pointer to the second string (substring).
Return value: ZF = 1 if the string ends with the substring; ZF = 0 if not.
Flag state: The function affects all flags.
Program source code
Intel 8086 assembly program example demonstrating the use of the StringEndsWithEx function to check a string ending.
title .286C .model small .stack 100h data segment public string db "Evgeny Dovgopolov\0" mName db "Dovgo\0" msg_true db "The string '%s' ends with '%s'\0" msg_false db "The string '%s' does not end with '%s'\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:[mName] ; 2nd: Push the address of variable mName onto the stack pushs ds:[string] ; 1st: Push the address of variable string onto the stack call StringEndsWithEx ; Call procedure StringEndsWithEx(string, mName) jne @False ; If ZF=0, jump to label @False pushs ds:[mName] ; 3rd: Push the address of variable mName onto the stack pushs ds:[string] ; 2nd: Push the address of variable string onto the stack leaax ds:[msg_true] ; 1st: Load the address of format string msg_true into register ds:ax jmp @Done ; Perform an unconditional jump to label @Done @False: pushs ds:[mName] ; 3rd: Push the address of variable mName onto the stack pushs ds:[string] ; 2nd: Push the address of variable string onto the stack leaax ds:[msg_false] ; 1st: Load the address of format string msg_false into register ds:ax @Done: call PrintFormatString ; Call the PrintFormatString procedure add sp, 4 ; Align the stack 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
The string 'Evgeny Dovgopolov' does not end with 'Dovgo'
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".