flat assembler
Message board for the users of flat assembler.

Index > Main > Comparing Strings

Author
Thread Post new topic Reply to topic
Christopher D



Joined: 25 Jun 2005
Posts: 17
Christopher D 26 Jun 2005, 01:28
Hi,
Can anyone help me to compare a string, I know how to do it
with numbers, but not strings and I need to work it out, also whats
the different between jmp and je, and long & short jumps?

Also, for the string one, I'm doing something like this

cmp eax,Hello

but this isnt working, help please!
Post 26 Jun 2005, 01:28
View user's profile Send private message Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: US
coconut 26 Jun 2005, 03:41
jmp will jump directly to specified label/location. the je/jne/jz/jnae etc instructions only jump depending on the FLAGS registers and if some other conditions are met.

for example, commonly you want to test if an API returned 0. all APIs return a value to eax register (check msdn for what specific return values mean). you would do something like:
Code:
invoke SomeAPI,blah,blah
or eax,eax    
jz returned_zero
    

ORing eax to eax does not change the value, it updates the zero flag; if eax is 0 the zero flag will be set to 1. the instruction JZ (jump if zero) jumps to label returned_zero only if zero flag was set.

as for the string comparing, see if this helps: http://board.flatassembler.net/topic.php?t=2633
Post 26 Jun 2005, 03:41
View user's profile Send private message Reply with quote
Christopher D



Joined: 25 Jun 2005
Posts: 17
Christopher D 26 Jun 2005, 04:41
Ok thanks,
but i still dont get the string thing on that page, would you beable to give me an example of useing the cmps command to compare 2 strings?
Post 26 Jun 2005, 04:41
View user's profile Send private message Reply with quote
shaolin007



Joined: 03 Sep 2004
Posts: 65
shaolin007 26 Jun 2005, 13:29
Christopher D wrote:
Ok thanks,
but i still dont get the string thing on that page, would you beable to give me an example of useing the cmps command to compare 2 strings?



Heres how to use c function strcmp in assembly. I'll let you hammer out the rest of the code.

Code:
format PE CONSOLE 4.0
entry MAIN

include '%fasminc%\win32a.inc'

section '.code' executable readable writeable

MAIN:

          cinvoke strcmp, string1, string2

section '.data' data readable writeable

string1         db "1234567890",0
string2         db "1234567890",0



section '.idata' import data readable writable

  library kernel,'KERNEL32.DLL',\
          msvcrt,'msvcrt.dll'

  import kernel,\
         ExitProcess,'ExitProcess'

  import msvcrt,\
         strcmp, 'strcmp'
    


If eax==0 afterwards then the strings are the same. Anything else is not equal to.
Post 26 Jun 2005, 13:29
View user's profile Send private message Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav 26 Jun 2005, 13:31
lstrcmp (the comparison is case sensitive) & lstrcmpi (the comparison is not case sensitive)

ps. you must download api book from download sections or order msdn
Post 26 Jun 2005, 13:31
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 26 Jun 2005, 13:52
Here is something for comparing strings I use in my CPU routine to determine the type of CPU:

Code:
   ...

   mov ecx,12                    ; Used for REPE
   mov ebx,0                     ; Used for cycling through known CPUs
   mov si,CPUIDMessage           ; Pointer to CPUID message
   mov di,KnownCPUs              ; First, then subsequent CPU manufacturer strings
        
.LoopForCPU:

   repe cmpsb                    ; Make the comparison
   or ecx,ecx                    ; Setup flags
   jnz .IncrementEBX             ; If not zero flag, then goto increment EBX


   ...
    


CMPSB: Compare Strings, byte-for-byte.

Compares strings byte-by-byte. DI and SI change in increments of decrements of 1, depending on the setting of the direction flag. Ordinarily, this instruction is used with REPE, REPNE, REPNZ, or REPZ instructions to repeat the comparison for a maximum of CX number of bytes. This instruction affects only the flags; no changes are made to the operands.

You can use ECX to return the value of the comparison. Anything other than zero they don't match.

I hope this helps...enjoy.


Last edited by smiddy on 26 Jun 2005, 13:58; edited 3 times in total
Post 26 Jun 2005, 13:52
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 26 Jun 2005, 13:53
Hy,
there is another Thread from Compare Strings

well, its in windows, but comparing strings can be done os independently...
Post 26 Jun 2005, 13:53
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.