1
votes

Hi. I am currently using MASM32 and am having some trouble multiplying things. I read the documentation and it makes no sense on why its not working.

    mov eax, input("X coordinate: ")
    mov ebx, input("Y coordinate: ")
    imul ebx, eax

    mov x, ebx
    print x

It should multiply the contents of ebx and eax and store the result in ebx, but it doesn't. Say you put in a 3 and a 6─all it prints is the 6.

1
Have you checked this question?iTech
@iTech that question pertains to mul. This question pertains to imul.lurker

1 Answers

0
votes

According to Intel documentation, when multiplying two 32-bit registers, the result is stored in the register combination edx:eax, which represents the 64-bit product. This is implemented even in x86-64 processors, for compatibility reasons, because during the time of creation, Intel processors only supported 32-bits.

First of all, in your code, you are printing ebx and not eax, which was expected on your part even if you lack knowledge of Intel documentary. This is the reason why your code is only printing 6, as 6 was the multiplicand in ebx. However, to achieve the correct answer, you still must only print edx:eax.

So, to fix this, you must either shorten the size of the multiplier and multiplicand to 16 bits (recommended way), or, find a way to print the entirety of edx:eax (may prove difficult depending on library imports).

Hope this helps.