0

I want to compare two strings, but the result is always true

    compara_v:
    lea si, x1_string
    lea di, c1_string
    cld
    repe cmpsb
    jz igual
    jmp diferente
    
igual:
        lea bx, True
        call printf_s
        jmp fim
        
diferente:
        lea bx, False
        call printf_s
        jmp fim
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 2
    You didn't set CX, so it might be only comparing 0 or 1 iterations. `repe cmpsb` only works for explicit-length strings (it can't also check for terminating zeros), so you need to know one of the lengths. – Peter Cordes Apr 10 '23 at 02:34
  • Possible duplicate: [How to compare two strings in nasm assembler with test or cmp correctly (x64)](https://stackoverflow.com/q/61192223) shows a loop or a `repe cmpsb` that sets RCX. (But since it's 64-bit code, it doesn't have to worry about segmentation, setting ES and DS, like in [Why does \`cmpsb\` not seem to compare the values of registers?](https://stackoverflow.com/q/47226326)) – Peter Cordes Apr 10 '23 at 02:41
  • 2
    Another possible duplicate: [Using cmpsb in assembly](https://stackoverflow.com/q/30447279) shows correct usage for explicit-length strings from int 21 / AH=0Ah buffers that have max/actual size bytes before the ASCII data. But we don't know what kind of strings you have (implicit length 0-terminated vs. explicit length), or whether ES and DS are already set, either by the environment in a `.com` executable, or by you in a `.exe`, so we don't know exactly what goes wrong or what you need to do. – Peter Cordes Apr 10 '23 at 02:46

0 Answers0