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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.