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.
mul
. This question pertains toimul
. – lurker