News:

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

help with comparisons of many strings at once

Started by axtens, May 09, 2007, 06:55:42 AM

Previous topic - Next topic

axtens

I'm designing a proc which receives a DWORD. Each bit of the DWORD is significant in that it specifies which of the sixteen strings should be compared.
So if the DWORD contains 0000000000001101, then I want to compare strings 0, 2 and 3.

so (thinking out loud)

theList = 0000000000001101
for n = 0 to length of some string used as reference (and maybe removed from theList)
for ecx = 0 to 15
  if ecx in theList
   if nth element of ecx'th string <> nth element of reference string
    return no_match
   endif
  endif
next
next


What I'm wanting to work out his how to know when ecx's value matches a bit point in theList.

Ideas?

Kind regards,
Bruce.

zooba

There's a number of ways:

bt  theList, ecx
jc  BitIsSet
jnc BitIsNotSet

(Obviously you don't need both jumps)

This will have different performance, I can't say off the top of my head whether it's better or not:

; Comment here to avoid alignment problems with code tags
    mov  ecx, 1
    jmp  Loop_Middle

Loop_Start:
    test theList, ecx
    jz   Loop_AfterProcessing
; Do whatever processing you want

Loop_AfterProcessing:
    add  ecx, ecx
    cmp  ecx, 00010000h
    je   Loop_Start

Loop_End:


At the Loop_AfterProcessing label you'd probably want to increment a pointer to point to the next string. See the various 'array of strings' or 'lookup table' posts for details on this.

Cheers,

Zooba :U