home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol8n19.zip / DDIV.ASM < prev    next >
Assembly Source File  |  1989-10-02  |  2KB  |  69 lines

  1.  
  2.         title   DDIV.ASM Double Precision Unsigned Divide
  3.         page    55,132
  4.  
  5. ; DDIV.ASM      Double Precision Unsigned Divide
  6. ;               for 8086, 8088, 80286, and 
  7. ;               80386 in real mode/16-bit protected mode
  8. ;
  9. ; Copyright (C) 1989 Ziff Communications Co.
  10. ; PC Magazine * Ray Duncan
  11. ;
  12. ; Call with:    DX:CX:BX:AX     = quad-precision dividend
  13. ;               SI:DI           = double-precision divisor
  14. ;
  15. ; Returns:      DX:AX           = double-precision quotient     
  16. ;               CX:BX           = double-precision remainder
  17. ;
  18. ; Destroys:     SI, DI
  19.  
  20. _TEXT   segment word public 'CODE'
  21.  
  22.         assume  cs:_TEXT
  23.  
  24.         public  ddiv
  25. ddiv    proc    near
  26.  
  27.         push    bp              ; save register
  28.         mov     bp,cx           ; BP = 3sw of dividend
  29.         mov     cx,32           ; initialize loop counter
  30.         clc                     ; carry flag initially clear
  31.  
  32. ddiv1:  rcl     ax,1            ; test this bit of dividend
  33.         rcl     bx,1
  34.         rcl     bp,1
  35.         rcl     dx,1
  36.         jnc     ddiv3           ; jump if bit was clear
  37.  
  38. ddiv2:  sub     bp,di           ; subtract divisor from dividend
  39.         sbb     dx,si
  40.         stc                     ; force carry flag set and
  41.         loop    ddiv1           ; shift it into forming quotient
  42.         jmp     ddiv5
  43.  
  44. ddiv3:  cmp     dx,si           ; dividend > divisor?
  45.         jc      ddiv4           ; no, jump
  46.         jne     ddiv2           ; yes, subtract divisor
  47.         cmp     bp,di
  48.         jnc     ddiv2           ; yes, subtract divisor
  49.  
  50. ddiv4:  clc                     ; force carry flag clear and
  51.         loop    ddiv1           ; shift it into forming quotient
  52.  
  53. ddiv5:  rcl     ax,1            ; bring last bit into quotient
  54.         rcl     bx,1
  55.  
  56.         mov     cx,bp
  57.         xchg    dx,bx           ; put quotient in DX:AX
  58.         xchg    cx,bx           ; put remainder in CX:BX
  59.  
  60.         pop     bp              ; restore register
  61.         ret                     ; and exit
  62.         
  63. ddiv    endp
  64.  
  65. _TEXT   ends
  66.  
  67.         end
  68.  
  69.