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
mov ax,[src1]
mov bx,[src2+2]
mul bx
mov ax,[src1+2]
mul bx
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
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

 Page 1 of 1 [ 3 post ]

Relevant Pages