home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol9n01.zip / DIDIV87.ASM < prev    next >
Assembly Source File  |  1989-09-26  |  2KB  |  70 lines

  1.         title   DIDIV87.ASM 80x87-based Signed Divide
  2.         page    55,132
  3.  
  4. ; DIDIV87.ASM   Double Precision Signed Integer Divide
  5. ;               for 80x87 coprocessor and 8086, 8088, 80286, or
  6. ;               80386 in real mode/16-bit protected mode
  7. ;
  8. ;               Be sure to call INIT87 routine first to test for 
  9. ;               coprocessor existence and to set rounding mode, 
  10. ;               precision, and exception masks!
  11. ;
  12. ; Copyright (C) 1989 Ziff Davis Communications
  13. ; PC Magazine * Ray Duncan
  14. ;
  15. ; Call with:    DX:CX:BX:AX     = quad-precision dividend
  16. ;               SI:DI           = double-precision divisor
  17. ;
  18. ; Returns:      DX:AX           = double-precision quotient     
  19. ;               CX:BX           = double-precision remainder
  20. ;
  21. ; Destroys:     nothing
  22.  
  23. _TEXT   segment word public 'CODE'
  24.  
  25.         assume  cs:_TEXT
  26.  
  27.         public  didiv
  28. didiv   proc    near
  29.  
  30.         push    dx                      ; put dividend on stack
  31.         push    cx
  32.         push    bx
  33.         push    ax
  34.  
  35.         push    si                      ; put divisor on stack
  36.         push    di
  37.  
  38.         mov     bx,sp                   ; make arguments addressable
  39.  
  40.         fild    dword ptr ss:[bx]       ; put divisor on coprocessor
  41.         fild    qword ptr ss:[bx+4]     ; put dividend on coprocessor
  42.  
  43.         fld     st(1)                   ; make copies of both
  44.         fld     st(1)
  45.  
  46.         fdivrp  st(1),st(0)             ; perform signed divide
  47.  
  48.         fistp   dword ptr ss:[bx]       ; unload quotient
  49.  
  50.         fprem                           ; calculate remainder
  51.  
  52.         fistp   dword ptr ss:[bx+4]     ; unload remainder
  53.         fstp    st(0)                   ; discard stack top
  54.  
  55.         pop     ax                      ; quotient into DX:AX
  56.         pop     dx
  57.  
  58.         pop     bx                      ; remainder into CX:BX
  59.         pop     cx
  60.  
  61.         add     sp,4                    ; clean up stack
  62.         ret                             ; and exit
  63.         
  64. didiv   endp
  65.  
  66. _TEXT   ends
  67.  
  68.         end
  69.  
  70.