News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Insensitive Comparer

Started by Twister, July 04, 2010, 11:02:52 PM

Previous topic - Next topic

Twister

I didn't see the MASM library already has this.

It's alpha stage.

(28) : error A2008: syntax error : dd
(29) : error A2008: syntax error : dd


.386
.model flat, stdcall
option casemap:none

.data

String1 db "MY NEWEST BROTHER BOBBY",0
String2 db "MY NEWEST BROtHER BOBBY",0

.code

StringCompareInsensitive proc Str1:DWORD, Str2:DWORD
pushad
xor ecx, ecx
mov esi, Str1
mov edi, Str2
mov eax, dword ptr [esi]
mov edx, dword ptr [edi]

xor eax, eax
;case
inc eax

mov Str1, eax
popad
mov eax, Str1
ret
@CAPITAL: dd 41424344h, 45464748h, 494A4B4Ch, 4D4E4F50h, 51525354h, 55565758h, 595A0000h ; TABLES
@LOWERCASE: dd 61626364h, 65666768h, 696A6B6Ch, 6D6E6F70h, 71727374h, 75767778h, 797A0000h ; TABLES
StringCompareInsensitive endp

start:
invoke StringCompareInsensitive, offset String1, offset String2
end start

oex

No I dont think it does however there is the suggestion in the help file that you convert the string to lower case and compare.... I have just done a work around for this function in one of my applications.... Changing case isnt very convenient....

@Capital: is a label not a variable

Put

Capital   db 41h,42h,43h,44h,45h,46h,47h,48h,49h,4Ah,4Bh,4Ch,4Dh,4Eh,4Fh,50h etc....

in the data section and it should work.... Note: db not dd.... dd is DWORD....

or

Capital   dd 41424344h, 45464748h, 494A4B4Ch, 4D4E4F50h, 51525354h, 55565758h, 595A0000h ; TABLES
Lowercase   dd 61626364h, 65666768h, 696A6B6Ch, 6D6E6F70h, 71727374h, 75767778h, 797A0000h ; TABLES

In the data section....


hmm It just also built when I put it below the ret without the colon (and @) however I dont know the syntax validity of that
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

Twister

Quote from: oex on July 04, 2010, 11:59:06 PM
hmm It just also built when I put it below the ret without the colon (and @) however I dont know the syntax validity of that

It wouldn't matter because it doesn't go over that code.

MichaelW

Integer values larger than a byte are stored in memory with the bytes reversed, so for example:

dd 41424344h

Would be stored as:

44h, 43h, 42h, 41h

Where:

db 41h,42h,43h,44h

Would be stored as:

41h, 42h, 43h, 44h

eschew obfuscation

Farabi

you can use lstrcmpi for this, but you can make your own if you want.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

oex

Ah awesome ty Onan :bg

Also yeah my bad forgot to reverse :lol I dont think it would have mattered in this instance though
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

jj2007

Quote from: Radio on July 04, 2010, 11:02:52 PM
I didn't see the MASM library already has this.

Just for clarity: There is no Microsoft Masm library; what you mean is the Masm32 library maintained by Hutch (95%) and this forum here (5%) ;-)

In case you are looking for speed, the MasmBasic library has a StringsDiffer (and a FilesDiffer) function:
include \masm32\MasmBasic\MasmBasic.inc ; http://www.masm32.com/board/index.php?topic=12460
.data
String1 db "MY NEWEST BROTHER BOBBY", 0
String2 db "MY NEWEST BROtHER BOBBY", 0

Init
.if StringsDiffer(offset String1, offset String2, 0) ; 0: case-sensitive
; StringsDiffer returns in edx the relative position where the strings differ
add edx, offset String2
MsgBox 0, edx, "They are different:", MB_OK
.else
MsgBox 0, offset String1, "Strings are equal", MB_OK
.endif
.if StringsDiffer(offset String1, offset String2, 1) ; 1: case-insensitive
add edx, offset String2
MsgBox 0, edx, "They are different:", MB_OK
.else
MsgBox 0, offset String1, "Strings are equal", MB_OK
.endif
Exit
end start