Humble Beginner's Question: How do I mul 2 dwords and display results 
Author Message
 Humble Beginner's Question: How do I mul 2 dwords and display results

I've been beating my head in with this one.
I'd like some kind soul to explain how to do this without using the
486 instruction set (No EAX). If you use 4 words to hold the product,
how do you display the results in decimal?
                        I would appreciate any help!
                                        -matt


Thu, 24 Sep 1998 04:00:00 GMT  
 Humble Beginner's Question: How do I mul 2 dwords and display results

Quote:

> I've been beating my head in with this one.
> I'd like some kind soul to explain how to do this without using the
> 486 instruction set (No EAX). If you use 4 words to hold the product,
> how do you display the results in decimal?

OK, so only 16-bit regs, right?

src1 dw ?,?
src2 dw ?,?
; Use DI:SI:CX:BP for temp storage of 64-bit result

saveSP dw ?

  mov ax,[src1]
  mov bx,[src2]
  mul bx
  mov bp,ax
  mov cx,dx
  mov ax,[src1+2]
  mul bx
  xor si,si
  xor di,di
  add cx,ax
  adc si,dx
  mov ax,[src1]
  mov bx,[src2+2]
  mul bx
  add cx,ax
  adc si,dx
  adc di,di
  mov ax,[src1+2]
  mul bx
  add si,ax
  adc di,dx     ; DI:SI:CX:BP has 64-bit result

  mov bx,10     ; Divisor to be able to display the result
  mov [saveSP],sp ; Remember stack position!

divloop:
  xor dx,dx
  mov ax,di
  div bx
  mov di,ax
  mov ax,si
  div bx
  mov si,ax
  mov ax,cx
  div bx
  mov cx,ax
  mov ax,bp
  div bx
  push dx       ; DX has remainder after the (very long) division!
  mov bp,ax
  or ax,cx
  or ax,si
  or ax,di
   jnz divloop

  mov cx,[saveSP]
disploop:
  pop dx
  add dl,'0'
  mov ah,2
  int 21h       ; Display digit in DL
  cmp cx,sp
   jne disploop

--

"almost all programming can be viewed as an exercise in caching"



Thu, 24 Sep 1998 04:00:00 GMT  
 Humble Beginner's Question: How do I mul 2 dwords and display results
Quote:

>I've been beating my head in with this one.
>I'd like some kind soul to explain how to do this without using the
>486 instruction set (No EAX). If you use 4 words to hold the product,
>how do you display the results in decimal?
>                    I would appreciate any help!
>                                    -matt

Sometimes I have these probs too. What I do then is making a little C program
and compile it. Using a good de{*filter*} you can see what code is generated (very
often it is crappy, but it works)
Optimize and adjust on your particular program and your problem is solved!
--
-----------------------------------------------------------------------
Arnout van der Kamp
Hardware & Software Engineer at Digital Infinity, Haarlem Holland
(currently working at the Laboratory for Clinical & Experimental Image
Processing, University Hospital Leiden)
-----------------------------------------------------------------------


Mon, 28 Sep 1998 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Comms Port Question from a humble Summer '87 programmer

2. why awk don't display the results?

3. Beginner's 'enum' question

4. Displaying *BIG* numbers (DWORDS)

5. Sorry it's beginner's question..

6. TK beginners question - how to 'beep'

7. where Sayed's humble envelope kicks, Ramsi orders near strange, durable colleges

8. Only a humble question....

9. What's a DWORD

10. takes a dword from eax and converts it in it's hexadecimal representation - ex

11. awk's mod operator % question (application: log base2 non-integer result)

12. question on Tcl's model of storing result

 

 
Powered by phpBB® Forum Software