954,490 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Word Multiplication Problem

Hello,

I need a little help for word multiplication, according to my notes, to multiply a word, we should put the multiplicand in AX, the multiplier in a register or memory variable and the result should appears in AX(low) and DX(high).

The problem is how to get the product ? It is found in two seperate registers, how to merge them together.

This is a simple example:

call GetDec
		        mov bx, ax
                        dec bx
			cwd
			imul bx


From the example above, the product is in AX and DX but how to access the product and save it in a memory variable?

Thanks in advance for your answer.

neutralfox
Junior Poster
124 posts since Mar 2009
Reputation Points: 6
Solved Threads: 0
 

If you have a 32 bit system you could just do something like

Either checking if it overflowed into dx or just zeroing everything out before hand

mov cx, dx
shl ecx, 16
mov cx, ax

Or you could set aside space on the stack something along the lines of

enter 0,4
....code goes here...
....multiplication code.....
mov [ebp - 2], dx
mov [ebp - 4], ax


And now your number resides at [ebp - 4]

sysop_fb
Light Poster
43 posts since Apr 2009
Reputation Points: 57
Solved Threads: 5
 

Hello, thanks for the answer, I have not tested your solution, because I got the solution by myself.

Solution:
Move 0 in eax
push ax
mov ax, dx
Make 16 left shift in eax, to push ax to the end
pop ax
move ax, in eax

Voila.

Anyway, thanks for the answer dude.

neutralfox
Junior Poster
124 posts since Mar 2009
Reputation Points: 6
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You