在汇编中查找子字符串

发布于 2024-10-05 21:12:55 字数 302 浏览 0 评论 0原文

我想知道是否有一种比我目前计划做的更有效的方法来在汇编中查找子字符串。

我知道字符串指令“scansb/scasw/scads”可以将 EAX 中的值与 EDI 寻址的值进行比较。但是,据我了解,使用这种方法一次只能搜索一个字符。

因此,如果我想在字符串“pleasehelpme”中找到“help”的位置,我可以使用 scansb 找到 h 的偏移量,然后跳转到另一个函数来比较余数。如果余数不正确,我会跳回 scansb 并尝试再次搜索,这次是在前一个偏移标记之后。

然而,我不想这样做,然后发现有一个更有效的方法。有什么建议吗?提前致谢

I'm wondering if there is a more efficient method to finding a substring in assembly then what I am currently planning to do.

I know the string instruction "scansb/scasw/scads" can compare a value in EAX to a value addressed by EDI. However, as far as I understand, I can only search for one character at a time using this methodology.

So, if I want to find the location of "help" in string "pleasehelpme", I could use scansb to find the offset of the h, then jump to another function where I compare the remainder. If the remainder isn't correct, I jump back to scansb and try searching again, this time after the previous offset mark.

However, I would hate to do this and then discover there is a more efficient method. Any advice? Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

硬不硬你别怂 2024-10-12 21:12:55

确实有更有效的方法,无论是指令方面还是算法方面。

如果您有硬件,则可以使用 sse 4.2 比较字符串函数,该函数非常快。查看概述 http://software.intel.com/sites/products/documentation/studio/composer/en-us/2009/compiler_c/intref_cls/common/intref_sse42_comp.htm 以及使用 C 内联函数的示例 http:// software.intel.com/en-us/articles/xml-parsing-accelerator-with-intel-streaming-simd-extensions-4-intel-sse4/

如果您有长子字符串或多个搜索模式,< a href="http://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string_search_algorithm" rel="nofollow">Boyer-Moore,Knuth-Morris-PrattRabin-Karp 算法可能更有效。

There are indeed more efficient ways, both instruction-wise and algorithmically.

If you have the hardware you can use the sse 4.2 compare string functions, which are very fast. See an overview http://software.intel.com/sites/products/documentation/studio/composer/en-us/2009/compiler_c/intref_cls/common/intref_sse42_comp.htm and an example using the C instrinsics http://software.intel.com/en-us/articles/xml-parsing-accelerator-with-intel-streaming-simd-extensions-4-intel-sse4/

If you have long substrings or multiple search patterns, the Boyer-Moore, Knuth-Morris-Pratt and Rabin-Karp algorithms may be more efficient.

筱武穆 2024-10-12 21:12:55

我认为没有更有效的方法(只能对此方法进行一些优化)。另外可能会引起兴趣。

I don't think there is a more efficient method (only some optimizations that can be done to this method). Also this might be of interest.

浅笑依然 2024-10-12 21:12:55

scansbstrcmp 的汇编变体,而不是 strstr 的汇编变体。如果你想要一个真正有效的方法,那么你必须使用更好的算法。

例如,如果您在长字符串中搜索,那么您可以尝试一些特殊的算法:http://en。 wikipedia.org/wiki/String_searching_algorithm

scansb is the assembly variant for strcmp, not for strstr. if you want a really efficient method, then you have to use better algorithm.

For example, if you search in a long string, then you could try some special algorithms: http://en.wikipedia.org/wiki/String_searching_algorithm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文