home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.asm.x86      Ahh, the lost art of x86 assembly      4,675 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 4,322 of 4,675   
   Paul Edwards to DJ Delorie   
   Re: 8086 32-bit multiply   
   23 Apr 21 20:16:04   
   
   From: mutazilah@nospicedham.gmail.com   
      
   On Saturday, April 24, 2021 at 9:36:28 AM UTC+10, DJ Delorie wrote:   
   > Paul Edwards  writes:   
   > > ; multiply cx:bx by dx:ax, result in dx:ax   
   > Such 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)   
      
   Thanks for the algorithm! I thought I might be able to do that,   
   but my brain started to melt down. Here's what I came up with,   
   which causes a hang, but at least it happened after I got the   
   results of some calculations. I'll see if I can figure out what   
   is happening.   
      
      
    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 bx   
   push cx   
   push si   
   push di   
      
   push ax   
   push bx   
      
    I think this multiples bx * ax and puts the upper 16 bits in ax   
    and lower 16 bits in bx   
   mul bx   
      
    Save upper 16 in si and lower 16 in di   
   mov si, ax   
   mov di, bx   
      
    This does the equivalent of bx * dx   
   pop bx   
   mov ax, dx   
   mul bx   
   mov dx, ax   
      
    Now we do cx * ax with upper 16 bits in ax and lower in cx   
   pop ax   
   mul cx   
      
    Now we need to add the results of those two multiplies together   
    lower 16 bits first, so we can get the carry   
   push bp ; ran out of registers!   
   mov bp, bx   
   mov bx, ax   
   mov ax, 1   
   add dx, cx   
   jc noone   
   mov ax, 1   
   noone:   
      
   push ax   
      
    Now the other lower 16 bits we saved   
   mov ax, 1   
   add dx, di   
   jc noone2   
   mov ax, 1   
   noone2:   
      
   push ax   
      
    Upper 16 bits   
   mov ax, bx   
   add bx, ax   
   pop ax   
   add bx, ax ; one carry   
   pop ax   
   add bx, ax ; the other carry   
   mov ax, bp   
   add bx, ax   
      
    store in proper output register   
   mov dx, bx   
      
   pop bp   
      
   pop di   
   pop si   
   pop cx   
   pop bx   
   pop bp   
   ret   
   f_lxmul@ endp   
      
      
   BFN. Paul.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca