1

I am new to LEGv8 and am trying to learn the syntax. However I am stuck on determining whether a string with a known length (that I calculated and stored in x2) is the same as another string with the same length. If I have one string in register x3 and another in register x4, how would I go about recursively comparing the two strings?

Thanks in advance for the help!

  • 1
    Recursion makes this massively harder than it needs to be. The natural implementation of `memcmp` (comparing 2 blocks of memory of known length) is a loop. I wouldn't recommend using recursion; it will be much slower than comparing 8 bytes at a time in a loop, until you get close to the end of the buffer and do single bytes, or an unaligned last 8 bytes. Even if LEGv8 has SIMD like regular AArch64, it's not easy to use for compare/branch loops, so plain integer is probably a good bet. – Peter Cordes Oct 17 '18 at 03:38
  • 1
    @PeterCordes Thank you for the reply! I realize that recursion makes this harder, but that is the point. I am trying to learn recursion using this prompt and also become familiar with LEGv8. I've done simpler projects and am now trying to challenge myself. I just need someone to help point me in the right direction! – thecolorfulcoder Oct 17 '18 at 05:23
  • I'd suggest something like a tree traversal where recursion is actually natural, or computing the Ackermann function ([What are good examples that actually motivate the study of recursion?](https://cseducators.stackexchange.com/a/4361)), or some other naturally-recursive thing with a base-case. It's just going to be weird to use recursion for `memcmp(a+1, b+1, n-1)`, but I guess you can. If you want a pointer in the right direction, look at AArch64 C compiler output for a recursive function. ([How to remove "noise" from GCC/clang assembly output?](https://stackoverflow.com/q/38552116)) – Peter Cordes Oct 17 '18 at 05:28

0 Answers0