I have this problem, when i run this sentence they enter in an infinite loop, and i don't know why ?

Can anybody help me?

Thanks !!                           ;)


str2 and str4 are locals

mov edi,sval(str2)
mov edx,sval(str4)


.WHILE (edi != edx)
        .IF edi > edx
            mov esi, edi
            sub esi, edx
            mov aux1, ustr$(esi)
            print aux1
        .ELSEIF
            mov esi, edx
            sub esi, edi
            mov aux2, ustr$(esi)
            print aux2
         .ENDIF
;.BREAK .IF aux1 == aux2
.ENDW
Posted on 2005-10-16 18:22:58 by chola
From what I can see, the value in edx is getting changed by the print macro.
That could be your problem.
Rags
Posted on 2005-10-16 19:12:36 by rags
i also think so. when you call a function or macro you must be prepared that the registers eax,ecx,edx might be changed. just save the register on the stack with a push&pop or better use ebx register instead of edx.

.WHILE (edi != edx)
        push edx
        .IF edi > edx
            mov esi, edi
            sub esi, edx
            mov aux1, ustr$(esi)
            print aux1
        .ELSE
            mov esi, edx
            sub esi, edi
            mov aux2, ustr$(esi)
            print aux2
        .ENDIF
        pop edx
.ENDW

or
.WHILE (edi != ebx)
        .IF edi > ebx
            mov esi, edi
            sub esi, ebx
            mov aux1, ustr$(esi)
            print aux1
        .ELSE
            mov esi, ebx
            sub esi, edi
            mov aux2, ustr$(esi)
            print aux2
        .ENDIF
.ENDW
Posted on 2005-10-17 07:44:58 by diablo2oo2
Nothing, the solucion that you put here, do the same, the loop is infinite, and don't stop.
i have a question when you use sub esi, ebx, where the instruccion put the result in esi, or in eax ??
Posted on 2005-10-17 13:36:24 by chola

Nothing, the solucion that you put here, do the same, the loop is infinite, and don't stop.
i have a question when you use sub esi, ebx, where the instruccion put the result in esi, or in eax ??


load it into a debugger (i like ollydbg) and see what happens in your loop. then you will also get the answear what happens with "sub esi,ebx"... ;)
you can learn a lot while watching your code in the debugger.
Posted on 2005-10-17 13:40:39 by diablo2oo2
I try whit this i't work but only if eax > ebx and don't know why? if eax < ebx the code don't work.
    :sad:

    mov eax,var2
    mov ebx,var4
    mov aux1, ustr$(eax)
.WHILE (eax != ebx)
        .IF eax > ebx
            sub eax,ebx
            mov aux1,ustr$(eax)
            mov eax,sval(aux1)
        .ELSE
            sub ebx,eax
            mov aux1, ustr$(ebx)
            mov ebx,sval(aux1)
        .ENDIF
.ENDW
    loc 10,24
    print "The Result Is: "
    loc 46,24
    print aux1
Posted on 2005-10-17 16:19:26 by chola
Try using EBX, ESI and EDI if you want their values to be kept intact. The EAX, ECX and EDX registers will be trashed by masm32's macros, Windows API calls, etc. For example you could use EDI and EBX.

Another thing, are those integers supposed to be signed? The .IF macro assumes unsigned integers by default. Use this for signed values:

.IF (SDWORD ptr edi) > (SDWORD ptr ebx)

Posted on 2005-10-17 17:15:06 by QvasiModo
I have problems using ESI and EDI, that why i use EAX, EBX and EDX, but i try again with that.


Try using EBX, ESI and EDI if you want their values to be kept intact. The EAX, ECX and EDX registers will be trashed by masm32's macros, Windows API calls, etc. For example you could use EDI and EBX.

Another thing, are those integers supposed to be signed? The .IF macro assumes unsigned integers by default. Use this for signed values:

.IF (SDWORD ptr edi) > (SDWORD ptr ebx)


Posted on 2005-10-18 09:00:06 by chola
What problems? I think you have to clear. You can't go to the doctor saying you are in pain, but don't know where the pain came from.  ;)
Posted on 2005-10-18 09:01:50 by roticv

I try whit this i't work but only if eax > ebx and don't know why? if eax < ebx the code don't work.

ustr$ and sval are altering EAX ?
Posted on 2005-10-18 21:52:18 by tenkey
This is the solution that i find, i don't know if is the correct way to do it, but it work.

;)

;Rutina para encontar el MCD

    mov eax,var2
    mov ebx,var4
    mov aux1, ustr$(eax)
.WHILE (eax != ebx)
        .IF eax > ebx
            sub eax,ebx
            mov aux1,ustr$(eax)
            mov eax,sval(aux1)
        .ELSE
            sub ebx,eax
            mov ebx,eax
            mov aux1, ustr$(ebx)
            mov ebx,sval(aux1)
        .ENDIF
.ENDW
    loc 10,24
    print "El M.C.D (Maximo Comun Divisor) es: "
    loc 46,24
    print aux1


Posted on 2005-10-26 08:08:43 by chola