StringCompareEx function
The StringCompareEx function performs a lexicographic comparison of two strings. 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.
Return value: AX = 0 and ZF=1 if the strings are equal. AX = 1 or -1 and ZF=0 if the strings are not equal.
Flag state: The function affects all flags.
Program source code
Intel 8086 assembly program example demonstrating the use of the StringCompareEx function to compare two strings passed through the stack lexicographically.
title .286C .model small .stack 100h data segment public string1 db "Dovgopolov Evgeny\0" string2 db "Dovgopolov Sergey\0" equal db "The strings are equal!\0" notEqual db "The strings are not equal!\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:[string2] ; 2nd: Push the address of variable string2 onto the stack pushs ds:[string1] ; 1st: Push the address of variable string1 onto the stack call StringCompareEx ; Call procedure StringCompareEx(string1, string2) := AX and ZF jne @StringsNotEqual ; If ZF=0, jump to label @StringsNotEqual pushs ds:[equal] ; Push the address of variable equal onto the stack jmp @Done ; Perform an unconditional jump to label @Done @StringsNotEqual: pushs ds:[notEqual] ; Push the address of variable notEqual onto the stack @Done: call WriteStringEx ; Call procedure WriteStringEx(value from 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 strings are not equal!
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".