home *** CD-ROM | disk | FTP | other *** search
/ PC Media 2 / PC MEDIA CD02.iso / share / prog / realasm1 / ftdiv.asm < prev    next >
Encoding:
Assembly Source File  |  1993-07-18  |  4.0 KB  |  103 lines

  1. .286
  2. ;================================================
  3. ; Divides REAL10's dst, src
  4. ;
  5. ;------------------------------------------------
  6. cseg          segment word public 'code'
  7.               assume  cs:cseg,ss:cseg
  8.               assume  ds:cseg,es:cseg
  9.  
  10.               include math.inc
  11.  
  12. ftdiv         proc    near uses ds es, dst:NPR10, src:NPR10
  13.               local   t:REAL10, dcopy[4]:WORD, result[4]:WORD
  14.  
  15.               pusha
  16.               mov     si, src
  17.               mov     di, dst
  18.  
  19.               invoke  ftzero, si                ; if src = 0.0
  20.               .IF ax == TRUE                    ;
  21.                  jmp     exit                   ; dst unchanged
  22.               .ENDIF                            ;
  23.  
  24.               invoke  ftzero, di                ; if dst = 0.0
  25.               .IF ax == TRUE                    ;
  26.                  jmp     exit                   ;
  27.               .ENDIF                            ;
  28. ;------------------------------------------------
  29. ; get resultant exponent and sign
  30. ;------------------------------------------------
  31.               mov     ax, word ptr [di]+8       ;
  32.               mov     bl, ah                    ;
  33.               and     bl, 80h                   ; BL = dst sign
  34.               and     ax, 7fffh                 ;
  35.               sub     ax, 3fffh                 ;
  36.  
  37.               mov     dx, word ptr [si]+8       ;
  38.               mov     bh, dh                    ;
  39.               and     bh, 80h                   ; BH = src sign
  40.               and     dx, 7fffh                 ;
  41.               sub     dx, 3fffh                 ;
  42.  
  43.               sub     ax, dx                    ; subtract binary exponents
  44.               add     ax, 3fffh                 ; add bias
  45.  
  46.               .IF ((bx == 8000h) || (bx == 80h)); if -dst, +src OR +dst, -src
  47.                  or      ax, 8000h              ; result is -ve
  48.               .ENDIF                            ;
  49.  
  50.               mov     word ptr [di]+8, ax       ;
  51. ;------------------------------------------------
  52. ;
  53. ;------------------------------------------------
  54.               invoke  movx, addr t, si, 5       ; don't violate src
  55.               lea     si, t                     ; ss::si addresses t
  56.  
  57.               invoke  clrx, addr result, 4      ; clear result
  58.  
  59.               invoke  movx, addr dcopy, di, 4   ; save copy of dst64
  60. ;------------------------------------------------
  61. ; shift and subtract division
  62. ;------------------------------------------------
  63.               mov     cx, 64                    ; for 64 bits
  64.  
  65.               .WHILE (cx)
  66.                  invoke  cmpxz, di, 4           ; if dst64 == 0
  67.                  .BREAK .IF (ax == TRUE)        ; exit loop
  68.  
  69.                  invoke  cmpx, di, si, 4        ;
  70.                  .IF ax != -1                   ; if dst64 >= src64
  71.                     invoke  subx, di, si, 4     ; dst64 -= src64
  72.                     or      word ptr result[0], 1 ; insert 1 in result
  73.                  .ENDIF                         ;
  74.  
  75.                  .IF cx > 1
  76.                     invoke  lshx, addr result, 4 ; shl result
  77.                     invoke  rshx, si, 4         ; shr divisor
  78.                  .ENDIF
  79.                  dec     cx                     ; continue
  80.               .ENDW
  81. ;------------------------------------------------
  82. ; normalise result
  83. ;------------------------------------------------
  84.               .WHILE (1)                        ;
  85.                  mov     ax, word ptr result[6] ;
  86.                  .BREAK .IF (ax & 8000h)        ;
  87.                  invoke  lshx, addr result, 4   ;
  88.               .ENDW                             ;
  89.  
  90.               invoke  movx, di, addr result, 4  ; res64 --> dst64
  91.  
  92.               invoke  cmpx, di, addr dcopy, 4   ;
  93.               .IF ax == 1                       ; if dst64 > original
  94.                  dec     word ptr [di]+8        ; exp--
  95.               .ENDIF                            ;
  96. exit:
  97.               popa
  98.               ret
  99. ftdiv         endp
  100.  
  101. cseg          ends
  102.               end
  103.