Date: 02-16-2022
Return to Index
created by gbSnippets
'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 qFreq, qStart, qStop As Quad, a$, b$, j As Long
a$ = "rrr"
b$ = "rrr"
CompPD(a$,b$)
End Function
Function CompPD(a As String, b As String) As Long
Local pa,pb As Byte Ptr, j As Long
pa = StrPtr(a):pb=StrPtr(b)
!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
!mov esi,[esi] 'add this line if a is a function parameter
!mov edi,[edi] 'add this line if b is a function parameter
!cmp esi,0 'Handle nul strings
!jne Skip1
!cmp edi,0
!je StringsMatch 'both are nul so they match
!jmp xit 'a is nul but b isn;t so they don't match
Skip1:
!cmp edi,0
!je 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 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 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 xit 'if not equal, we're done
CheckOddWord:
!test ecx,2 'is there an odd Word to handle?
!jz 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 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 StringsMatch
lp1:
!mov eax,[esi+ecx-4] 'get next dword
!cmp eax,[edi+ecx-4] 'compare with other string
!jne xit 'if not equal then finished
!sub ecx,4 'do next dword
!jnz 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_01115
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm