Word Multiplication Problem

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Mar 2009
Posts: 123
Reputation: neutralfox is an unknown quantity at this point 
Solved Threads: 0
neutralfox neutralfox is offline Offline
Junior Poster

Word Multiplication Problem

 
0
  #1
Apr 23rd, 2009
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:

  1. call GetDec
  2. mov bx, ax
  3. dec bx
  4. cwd
  5. 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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 39
Reputation: sysop_fb is an unknown quantity at this point 
Solved Threads: 5
sysop_fb sysop_fb is offline Offline
Light Poster

Re: Word Multiplication Problem

 
0
  #2
Apr 24th, 2009
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
  1. mov cx, dx
  2. shl ecx, 16
  3. mov cx, ax


Or you could set aside space on the stack something along the lines of
  1. enter 0,4
  2. ....code goes here...
  3. ....multiplication code.....
  4. mov [ebp - 2], dx
  5. mov [ebp - 4], ax

And now your number resides at [ebp - 4]
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 123
Reputation: neutralfox is an unknown quantity at this point 
Solved Threads: 0
neutralfox neutralfox is offline Offline
Junior Poster

Re: Word Multiplication Problem

 
0
  #3
Apr 24th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Assembly Forum


Views: 466 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Assembly
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC