home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol8n20.zip / MPIMUL.ASM < prev    next >
Assembly Source File  |  1989-10-13  |  3KB  |  83 lines

  1.         title   MPIMUL.ASM Multiple-Precision Signed Multiply
  2.         page    55,132
  3.  
  4. ; MPIMUL.ASM    Multiple-Precision Signed Multiply
  5. ;               for Intel 8086, 8088, 80286, and
  6. ;               80386 in real mode/16-bit protected mode.
  7. ;               Requires MPNEG.ASM (multiple-precision
  8. ;               2's complement) and MPMUL1.ASM (multiple-
  9. ;               precision unsigned integer multiply).
  10. ;
  11. ; Copyright (C) 1989 Ziff Davis Communications
  12. ; PC Magazine * Ray Duncan
  13. ;
  14. ; Call with:    DS:SI   = address of source operand
  15. ;               ES:DI   = address of destination operand
  16. ;               CX      = operand length in bytes
  17. ;
  18. ;               Assumes direction flag is clear at entry
  19. ;               Assumes DS = ES <> SS
  20. ;               Assumes CX <= 255
  21. ;
  22. ; Returns:      ES:DI   = address of product
  23. ;
  24. ;               NOTE: Buffer for destination operand must be
  25. ;               twice as long as the actual operand, because
  26. ;               it will receive a double-precision result.
  27. ;
  28. ; Destroys:     AX (other registers preserved)
  29.  
  30. _TEXT   segment word public 'CODE'
  31.  
  32.         extrn   mpmul1:near 
  33.         extrn   mpneg:near
  34.  
  35.         assume  cs:_TEXT
  36.  
  37.         public  mpimul
  38. mpimul  proc    near
  39.  
  40.         push    bx                      ; save registers
  41.  
  42.         mov     bx,cx                   ; take Exclusive-OR of
  43.         mov     al,[si+bx-1]            ; signs of operands
  44.         xor     al,[di+bx-1]
  45.         pushf                           ; save sign of result           
  46.  
  47.         test    byte ptr [si+bx-1],80h  ; source operand negative?
  48.         jz      mpim1                   ; no, jump
  49.  
  50.         push    di                      ; yes, flip sign of 
  51.         call    mpneg                   ; source operand
  52.         pop     di
  53.  
  54. mpim1:  test    byte ptr [di+bx-1],80h  ; destination operand negative?
  55.         jz      mpim2                   ; no, jump
  56.         push    si                      ; yes, flip sign of
  57.         mov     si,di                   ; destination operand
  58.         call    mpneg
  59.         pop     si
  60.  
  61. mpim2:  call    mpmul1                  ; perform unsigned multiply
  62.  
  63.         popf                            ; retrieve sign of result
  64.         jns     mpim3                   ; jump, result is positive
  65.  
  66.         push    si                      ; operand signs were not
  67.         push    cx                      ; same, make result negative
  68.         mov     si,di
  69.         shl     cx,1
  70.         call    mpneg
  71.         pop     cx
  72.         pop     si
  73.  
  74. mpim3:  pop     bx                      ; restore register
  75.         ret                             ; back to caller
  76.  
  77. mpimul  endp
  78.  
  79. _TEXT   ends
  80.  
  81.         end
  82.  
  83.