![]() |
[FASM] Compare 2 strings - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Assembly (https://sinister.ly/Forum-Assembly) +--- Thread: [FASM] Compare 2 strings (/Thread-FASM-Compare-2-strings--169511) |
[FASM] Compare 2 strings - Houston1337 - 09-15-2022 Code: include 'win32ax.inc' str1 db '1111111111',0 str2 db '1111111112',0 start: stdcall CmpStr,str1,str2 test eax,eax jz not_the_same invoke MessageBox,0,'Both strings are alike!!','FASM',MB_OK jmp exit not_the_same: invoke MessageBox,0,'Both strings are Wrong','FASM',MB_OK exit:invoke ExitProcess,0 proc CmpStr uses esi edi ecx,str1,str2; returns 0 when strings are not the same. cld mov ecx,0ah mov esi,[str1] mov edi,[str2] repe cmpsb jnz @f mov eax,-1 ret @@: xor eax RE: [FASM] Compare 2 strings - Endeavor - 12-12-2022 Not sure if you need explanation, but here is a quick one: The code compares two strings, str1 and str2, and displays a message indicating whether they are the same or not. The CmpStr procedure is defined at the end of the code. It takes two string arguments (str1 and str2) and compares them byte by byte. If the strings are the same, it returns a non-zero value in the eax register. If the strings are not the same, it returns a zero value in eax. After calling CmpStr, the code checks the value in eax using the test instruction and jumps to the not_the_same label if the strings are not the same. Otherwise, it displays a message indicating that the strings are the same and exits the program. RE: [FASM] Compare 2 strings - Confidential - 02-14-2023 (12-12-2022, 10:15 AM)Endeavor Wrote: Not sure if you need explanation, but here is a quick one: Quote:If the strings are the same, it returns a non-zero value in the eax register.The code actually returns -1 in the eax register if the strings are the same, not a non-zero value. |