0

I am running into an issue with my code where I have created an infinite loop, though I have an exit within the loop.

I first initialize str1 and str2 and mov them into registers:

mov ecx, offset str1
mov edx, offset str2

Then, myloop runs, moving a character from ecx into cl and a character from edx into dl, increments ecx and edx for the next pass of the loop, compares cl to 0, for the null terminating character of str1. If this is true, then the loop SHOULD exit. If this is not true, then cl and dl are compared for the same character and the loop continues or exits if they are not equal.

myloop:
        mov cl, BYTE PTR [ecx]
        mov dl, BYTE PTR [edx]
        inc ecx
        inc edx
        cmp cl, 0
        je exit
        cmp cl, dl
        jne exit
        jmp myloop
    
exit:
        push offset str1
        push offset str2
        push offset format_s
        call printf

I used this article for reference and thought I understood it well up until my computer sounded like a helicopter about to take off...

Topher
  • 1
  • `cl` is the low byte of `ecx`; you're overwriting the low byte of your pointers with char data. Use a debugger to single-step your code and watch register values change. – Peter Cordes Nov 10 '21 at 18:03

0 Answers0