Date: 02-16-2022
Return to Index
created by gbSnippets
'Credit
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
Function PBMain() As Long
#Register None
Register i As Long
Local j As Long
Local qFreq, qStart, qStop As Quad, a$, b$
a$ = "rr "
b$ = "rr "
Local pa,pb As Byte Ptr
pa = StrPtr(a):pb=StrPtr(b)
'replace this next line with the ASM
' If a$ = b$ Then j = 0
!pushad
!mov j,1 'assume the strings don't match
!mov esi,a 'get the address of a
!mov edi,b 'get the address of b
!cmp esi,0 'Handle nul strings
!jne short Skip1
!cmp edi,0
!je short StringsMatch 'both are nul so they match
!jmp short xit 'a is nul but b isn;t so they don't match
Skip1:
!cmp edi,0
!je short xit 'b is nul an a isn't so they don't match
'else both are not nul so do the main compare
CheckOddByte:
!mov ecx,[esi-4] 'get length of string a
!cmp ecx,[edi-4] 'same length as string b?
!jne short xit 'if the lengths aren't the same then the strings don't match so we're finished
!test ecx,1 'is there an odd byte to handle?
!jz short CheckOddWord
!dec ecx 'adjust count for the 1 character just done
!mov al,[esi+ecx] 'get the odd byte
!cmp al,[edi+ecx] 'compare with the other string
!jne short xit 'if not equal, we're done
CheckOddWord:
!test ecx,2 'is there an odd Word to handle?
!jz short CheckDwords
!sub ecx,2 'adjust count for the 2 characters just done
!mov ax,[esi+ecx] 'get the odd word
!cmp ax,[edi+ecx] 'compare with the other string
!jne short xit 'if not equal, we're done
CheckDwords:
'we now have strings with lengths of whole dwords
!test ecx,-1 'anything left to do? (Strings maye have been <4 characters)
!jz short StringsMatch
lp1:
!mov eax,[esi+ecx-4] 'get next dword
!cmp eax,[edi+ecx-4] 'compare with other string
!jne short xit 'if not equal then finished
!sub ecx,4 'do next dword
!jnz short lp1 'if zero then finished and strings must match
StringsMatch:
!mov j,0 'flag that the strings match
xit:
!popad
'At this point, if j = 0 then the strings are identical
If j = 0 Then ? a$ + " " + b$ + " Equal"
If j <> 0 Then ? a$ + " " + b$ + " Not Equal"
End Function
'gbs_01113
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm