Search code examples
masmmasm32

MASM using registers as expressions between mod operator


I am completely newbie in masm32 and I want to realize such idea which is described in following line of (incorrect) code :

mov ebx,(eax mod any_number)

Compiler gives me error A2026 : constant expected

I read that mod operation cannot be used between registers, so which methods will help me to perform same idea ?

Hope for your help.


Solution

  • 9 % 5 = 4 What does Modulus mean? It is the remainder after you divide 2 numbers

        mov     eax, 9 mod 5
    

    or

    xor     edx, edx
    mov     eax, 9
    mov     ecx, 5
    div     ecx
    

    now edx contain the Modulus