Jump to content
  • Advertisement
Sign in to follow this  
Effection

ASM string comparison

This topic is 4137 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to be able to compare the first 3 characters of a string, the pointer of the string is held in EAX and i have no clue how to do this, can anyone post some example code or anything to help me?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Effection
I want to be able to compare the first 3 characters of a string, the pointer of the string is held in EAX and i have no clue how to do this, can anyone post some example code or anything to help me?


Compare them to what?

Share this post


Link to post
Share on other sites
If you are talking about x86 assembly, then there is the cmps instruction. If you always want to compare 3 bytes, there might be faster and more clever ways of doing it.

Share this post


Link to post
Share on other sites
the following works fine for me in visual studio inline assembly.


char* str1 = "Hello";
char* str2 = "Hell and back.";
int equal = 0;
__asm {
mov esi, str1 // mov str1 into register
mov edi, str2 // mov str2 into register
mov ecx, 3 // only compare 3 items
repz cmpsb // compare the 3 items, cmpsb implicitly uses esi, edi, repz implicitly uses ecx
jnz end0 // jump if not equal
mov equal, 1 // if we get here they are equal
end0:
}
cout << "String equal? " << (equal == 1 ? "TRUE" : "FALSE") << endl;



Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!