; multiply cx:bx by dx:ax, result in dx:ax
; multiply cx:bx by dx:ax, result in dx:ax
[x8086 only]
; multiply cx:bx by dx:ax, result in dx:axthe result of 32*32 bit doesn't fit into 32 bit.
either go with the given limits (16*16 bit) or
build a cascade with intermediate variables aka
MUL-ADD chains.
Paul Edwards <muta...@nospicedham.gmail.com> writes:
; multiply cx:bx by dx:ax, result in dx:axSuch would have three multiplies and a few adds:
LSW = bx * ax (lower 16, save upper 16 in XX)
MSW = bx * dx + cx * ax + XX (from lsw)
[x8086 only]
; multiply cx:bx by dx:ax, result in dx:axthe result of 32*32 bit doesn't fit into 32 bit.
Good point. I didn't think of that. I can't multiply
17 bits by 17 bits, one of the registers needs to
be 0. But I assume I need to at least overflow in
a predictable manner.
either go with the given limits (16*16 bit) or
build a cascade with intermediate variables aka
MUL-ADD chains.
See my most recent post. :-)
Hi.
Since 1994 I have been working on a project to
create a public domain version of MSDOS, called
PDOS. There is an 8086 version and an 80386
version which can be found here:
http://pdos.sourceforge.net/
I took some shortcuts along the way to get it to
work at all, and one of those has finally bitten me.
I'm getting incorrect results from this:
https://sourceforge.net/p/pdos/gitcode/ci/master/tree/pdpclib/dossupa.asm
; multiply cx:bx by dx:ax, result in dx:ax
public __I4M
__I4M:
public __U4M
__U4M:
public f_lxmul@
f_lxmul@ proc
push bp
mov bp,sp
push cx
push ax
mul cx
mov cx, ax
pop ax
mul bx
add dx, cx
pop cx
pop bp
ret
f_lxmul@ endp
On Saturday, April 24, 2021 at 10:51:35 AM UTC+10, wolfgang kern wrote:
[x8086 only]
; multiply cx:bx by dx:ax, result in dx:axthe result of 32*32 bit doesn't fit into 32 bit.
Good point. I didn't think of that. I can't multiply
17 bits by 17 bits, one of the registers needs to
be 0. But I assume I need to at least overflow in
a predictable manner.
Paul Edwards wrote:
Hi.
Since 1994 I have been working on a project to
create a public domain version of MSDOS, called
PDOS. There is an 8086 version and an 80386
version which can be found here:
http://pdos.sourceforge.net/
I took some shortcuts along the way to get it to
work at all, and one of those has finally bitten me.
I'm getting incorrect results from this:
https://sourceforge.net/p/pdos/gitcode/ci/master/tree/pdpclib/dossupa.asm
; multiply cx:bx by dx:ax, result in dx:ax
public __I4M
__I4M:
public __U4M
__U4M:
public f_lxmul@
f_lxmul@ proc
push bp
mov bp,sp
push cx
push ax
mul cx
mov cx, ax
pop ax
mul bx
add dx, cx
pop cx
pop bp
ret
f_lxmul@ endp
As several have noted, the code above is missing at least one MUL!
Please test it, then feel free to use (with or without attribution) this totally untested but reasonably efficent/short code:
mov si,ax
mov di,dx
mul cx ;; hi * lo
xchg ax,di ;; First mul saved, grab org dx
mul bx ;; lo * hi
add di,ax ;; top word of result
mov ax,si ;; retrieve original AX
mul bx ;; lo * lo
add dx,di
At this point DX:AX has the low 32 bits of the multiplication result.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 286 |
Nodes: | 16 (2 / 14) |
Uptime: | 87:28:44 |
Calls: | 6,496 |
Calls today: | 7 |
Files: | 12,100 |
Messages: | 5,277,163 |