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

  1. .286
  2. ;=======================================
  3. ; Miscellaneous
  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. ;================================================
  13. ; Test REAL10 for 0.0
  14. ;
  15. ; Returns AX = TRUE if 0.0, else AX = FALSE
  16. ;------------------------------------------------
  17. ftzero        proc    near uses si, dst:NPR10
  18.  
  19.               mov     si, dst
  20.               mov     ax, word ptr [si]+8
  21.               and     ax, 7fffh
  22.               or      ax, word ptr [si]+6
  23.               or      ax, word ptr [si]+4
  24.               or      ax, word ptr [si]+2
  25.               or      ax, word ptr [si]+0
  26.               .IF ax == 0
  27.                  mov     ax, TRUE
  28.               .ELSE
  29.                  mov     ax, FALSE
  30.               .ENDIF
  31.               ret
  32. ftzero        endp
  33.  
  34. ;================================================
  35. ; Check if REAL10's are of equal magnitude except
  36. ; for sign.
  37. ;
  38. ; If equal, returns AX = TRUE, else AX = FALSE
  39. ;------------------------------------------------
  40. ftequal       proc    near uses si di, x:NPR10, y:NPR10
  41.  
  42.               mov     si, x
  43.               mov     di, y
  44.  
  45.               invoke  cmpx, si, di, 4
  46.               .IF ax != 0
  47.                  mov     ax, FALSE
  48.                  jmp     exit
  49.               .ENDIF
  50.  
  51.               mov     ax, word ptr [si]+8
  52.               and     ax, 7fffh
  53.               mov     si, word ptr [di]+8
  54.               and     si, 7fffh
  55.  
  56.               .IF ax == si
  57.                  mov     ax, TRUE
  58.               .ELSE
  59.                  mov     ax, FALSE
  60.               .ENDIF
  61. exit:
  62.               ret
  63. ftequal       endp
  64.  
  65. ;================================================
  66. ; Check if a REAL10 is within exponent range of
  67. ; +64 < exp < -64
  68. ;
  69. ; Returns: AX = TRUE, if within range
  70. ;    else: AX = FALSE
  71. ;------------------------------------------------
  72. ftrange       proc    near uses bx si, dst:NPR10
  73.  
  74.               mov     si, dst                   ;
  75.               mov     ax, TRUE                  ; assume within range
  76.  
  77.               mov     bx, word ptr [si]+8       ;
  78.               and     bx, 7fffh                 ; remove sign
  79.               sub     bx, 3fffh                 ; remove bias
  80.  
  81.               .IF ((SWORD PTR bx >= MAXEXPONENT) || \
  82.                    (SWORD PTR bx <= MINEXPONENT))
  83.                  mov     ax, FALSE
  84.               .ENDIF
  85.  
  86.               ret
  87. ftrange       endp
  88.  
  89. ;================================================
  90. ; Normalise a REAL10
  91. ;
  92. ;------------------------------------------------
  93. ftnormal      proc    near uses ax si, dst:NPR10
  94.  
  95.               mov     si, dst
  96.               mov     ax, word ptr [si]+0
  97.               or      ax, word ptr [si]+2
  98.               or      ax, word ptr [si]+4
  99.               or      ax, word ptr [si]+6
  100.  
  101.               .IF (ax)
  102.                  .WHILE ( !(word ptr [si]+6 & 8000h) )
  103.                     dec     word ptr [si]+8
  104.                     invoke  lshx, si, 4
  105.                  .ENDW
  106.               .ELSE
  107.                  mov     word ptr [si]+8, 0
  108.               .ENDIF
  109.  
  110.               ret
  111. ftnormal      endp
  112.  
  113. ;================================================
  114. ; Change sign of a REAL10
  115. ;
  116. ;------------------------------------------------
  117. ftsign        proc    near uses si, dst:NPR10
  118.  
  119.               mov     si, dst
  120.               xor     word ptr [si]+8, 8000h
  121.  
  122.               ret
  123. ftsign        endp
  124.  
  125. ;================================================
  126. ; compare REAL10's x, y
  127. ;
  128. ; Returns: AX = 1,  if x > y
  129. ;              -1,  if x < y
  130. ;               0,  if x == y
  131. ;------------------------------------------------
  132. ftcomp        proc    near uses bx si di, x:NPR10, y:NPR10
  133.  
  134.               mov     si, x
  135.               mov     di, y
  136.  
  137.               invoke  ftequal, si, di
  138.               .IF ax == TRUE
  139.                  xor     ax, ax
  140.                  jmp     exit
  141.               .ENDIF
  142.  
  143.               invoke  ftzero, si
  144.               mov     bx, ax
  145.               invoke  ftzero, di
  146.  
  147.               .IF ((ax == TRUE) && (bx == FALSE)) ; if y == 0, x != 0
  148.                  mov     ax, 1
  149.                  jmp     exit
  150.               .ELSEIF ((ax == FALSE) && (bx == TRUE)) ; if y != 0, x == 0
  151.                  mov     ax, -1
  152.                  jmp     exit
  153.               .ENDIF
  154.  
  155.               mov     ax, word ptr [si]+8
  156.               and     ax, 7fffh
  157.               mov     bx, word ptr [di]+8
  158.               and     bx, 7fffh
  159.  
  160.               .IF (SWORD ptr ax > SWORD ptr bx)
  161.                  mov     ax, 1
  162.                  jmp     exit
  163.               .ELSEIF (SWORD ptr bx > SWORD ptr ax)
  164.                  mov     ax, -1
  165.                  jmp     exit
  166.               .ENDIF
  167.  
  168.               invoke  cmpx, si, di, 4
  169. exit:
  170.               ret
  171. ftcomp        endp
  172.  
  173. ;================================================
  174. ; swap two REAL10's
  175. ;
  176. ;------------------------------------------------
  177. ftswap        proc    near  uses si di, dst:NPR10, src:NPR10
  178.               local   t:REAL10
  179.  
  180.               mov     di, dst
  181.               mov     si, src
  182.               invoke  movx, addr t, si, 5      ;   t <-- src
  183.               invoke  movx, si, di, 5          ; src <-- dst
  184.               invoke  movx, di, addr t, 5      ; dst <-- t
  185.  
  186.               ret
  187. ftswap        endp
  188.  
  189. cseg          ends
  190.               end
  191.