Search code examples
assemblyx86masm

X86 assembly mul error masm


A simple question , why doesn't this work:

    mov ebx,m[edx*4]
    mov eax,conv[edx*4]
    mul ebx

I checked m[edx*4] it has 2 (what should be there) same for conv[edx*4].

It's basically just a 2*3.

m and conv are dd 2500 dup(?) <---- Thats why It doesn't work ?


Solution

  • I try to follow: Check what the 32 bit value is at memory location m and conv What is the value of edx when you start mov ebx,m[edx*4] Check if the expected values in ebx and eax are correct Edx will be overridden because MUL and IMUL instructions stores the result in EDX and EAX https://en.wikipedia.org/wiki/X86_instruction_listings

    MUL is used for unsigned multiplications, IMUL for signed multiplications. This means that, in contrary what Jester says: for 32 bits operands you use MUL (unsigned), for 31 bits with sign in 32th bit you use IMUL.

    If this all is ok, you should have in edx = 0 and eax = 6 if m[edx*4] = 2 and conv[edx*4] = 3 (or vice versa) mind that conv and m are 32 bits, with the least significant byte in the lowest memory location.

    correct me if I'm wrong.