flat assembler
Message board for the users of flat assembler.
Index
> Main > Comparing Strings |
Author |
|
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 |
|||
26 Jun 2005, 03:41 |
|
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? |
|||
26 Jun 2005, 04:41 |
|
shaolin007 26 Jun 2005, 13:29
Christopher D wrote: Ok thanks, 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. |
|||
26 Jun 2005, 13:29 |
|
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 |
|||
26 Jun 2005, 13:31 |
|
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 |
|||
26 Jun 2005, 13:52 |
|
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... |
|||
26 Jun 2005, 13:53 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.