home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / 8087_SAV.ASM < prev    next >
Assembly Source File  |  1997-07-05  |  3KB  |  76 lines

  1. ;  +++Date last modified: 05-Jul-1997
  2.  
  3. ; By: Jeffrey Nonken 
  4.  
  5.         page    60,132
  6.         .286
  7.  
  8. _text   segment byte public 'code'
  9. _text   ends
  10. _data   segment  word public 'data'
  11. _data   ends
  12. const   segment  word public 'const'
  13. const   ends
  14. _bss    segment  word public 'bss'
  15. _bss    ends
  16. dgroup  group   const,  _bss,   _data
  17.         assume  cs: _text, ds: nothing
  18.  
  19. _data   segment  word public 'data'
  20.         even
  21. env_8087        dw      47 dup (?)
  22. norm_8087       dw      177fh
  23. _data   ends
  24.  
  25. _text   segment byte public 'code'
  26. ;
  27. ; This code saves the 80x87 enviroment and sets up our own. First, this
  28. ; assumes you are running an 80287; the 8087 may require more FWAIT
  29. ; operations. Second, I decided that I didn't want to handle exceptions, so
  30. ; I simply disabled them. That means that if the 80x87 gets an invalid result
  31. ; (such as divide-by-zero) the 80x87 will continue to run and will produce
  32. ; invalid results until the end of your current calculation. Anything that
  33. ; depends on the results will, of course, also be invalid. If you want
  34. ; exceptions to be handled, get documentation for the 80x87 and you will
  35. ; see how to set norm_8087 (above) to suit your needs. If you are running
  36. ; an 8087 and don't know where to put FWAIT instructions, you can always
  37. ; add one after each floating-point instruction. NOTE: FWAIT is synonymous
  38. ; to WAIT. They are the same instruction.
  39. ;
  40. ; This was written for TURBO C and will also work with MSC. It should work
  41. ; with any programming language with no more than minor changes in the
  42. ; label names or the interface. Consult your compiler manual for more detail.
  43. ; I wrote this so it would work with either the tiny or small models.
  44. ; Actually, it will probably work with any of the models. You should be
  45. ; able to assemble this with MASM and link it right in.
  46. ;
  47. ; extern save_8087();
  48. ; extern restore_8087();
  49. ;
  50.         public  _save_8087
  51. _save_8087      proc    near
  52.         cli                             ; no interruptions!
  53.         lea     bx,dgroup:env_8087      ; point to save area
  54.         fwait                           ; make sure processor is ready
  55.         fnsave  [bx]                    ; save the 8087 environment
  56.         lea     bx,dgroup:norm_8087     ; point to our new 8087 setup
  57.         mov     ax,[bx]                 ; get it
  58.         fldcw   [bx]                    ; set it
  59.         fwait
  60.         sti                             ; restore interrupts
  61.         ret
  62. _save_8087      endp
  63.  
  64.         public  _restore_8087
  65. _restore_8087   proc    near
  66.         cli                             ; no interruptions!
  67.         lea     bx,dgroup:env_8087      ; point to saved 8087 stuff
  68.         frstor  [bx]                    ; restore the 8087 environment
  69.         sti                             ; restore interrupts
  70.         ret
  71. _restore_8087   endp
  72.  
  73. _text   ends
  74.  
  75.         end
  76.