www.digitalmars.com         C & C++   DMDScript  

c++ - Minor inline ASM error

reply "KarL" <someone somewhere.org> writes:
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Pinched the following code from somewhere:
#include <dos.h>////      Save FPU state.////      This uses a magic =
spell taken from Intel application note AP-113.//void fpusave (char far* =
t){    //_ES =3D FP_SEG (t);    //_BX =3D FP_OFF (t);    __asm les bx,t  =
  __asm  fnstcw  es:[bx]     // save IEM bit status    __asm  nop        =
         // delay while control word saved    __asm  fndisi              =
// disable BUSY signal    __asm  mov     ax, es:[bx] // get original =
control word in AX    __asm  fsave   es:[bx]     // save FPU state    =
__asm  fwait               // wait for save to complete    __asm  mov    =
 es:[bx],ax  // put original control word in saved state}
////      Restore FPU state.//void fpurest (char far* t){    //_ES =3D =
FP_SEG (t);    //_BX =3D FP_OFF (t);    __asm les bx,t    __asm frstor =
es:[bx]}
Found the compiler cannot recognise fndisi instruction.  Compiles with =
MS VC++ 1.5 and above and BCC as well.

When Obj2asmed the code generated by BC or VC,

fndisi   (db e1)

is being intepreted as

fdisi    (9b db e1)

Don't ask me what they mean as I haven't read into the Intel data book =
yet...
May 05 2003
next sibling parent "KarL" <someone somewhere.org> writes:
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

The following code will now generate identical obj file by MSVC, DMC/SC =
and BC:
void fpusave (char far* t){#if defined(__BORLANDC__)    _ES =3D FP_SEG =
(t);    _BX =3D FP_OFF (t);#else     // MSVC or DMC/SC    __asm les =
bx,t#endif    __asm fnstcw  es:[bx]     // save IEM bit status    __asm =
nop                 // delay while control word saved
#if defined(__SC__)    __emit__(0xdb,0xe1);#else    __asm fndisi         =
     // disable BUSY signal#endif
    __asm mov     ax, es:[bx] // get original control word in AX    =
__asm fsave   es:[bx]     // save FPU state    __asm fwait               =
// wait for save to complete    __asm mov     es:[bx],ax  // put =
original control word in saved state}
void fpurest (char far* t){#if defined(__BORLANDC__)    _ES =3D FP_SEG =
(t);    _BX =3D FP_OFF (t);#else     // MS or SC    __asm les bx,t#endif
    __asm frstor es:[bx]}
May 05 2003
prev sibling next sibling parent reply "Walter" <walter digitalmars.com> writes:
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

You're right. That instruction only does anything on the original 8087, =
and isn't even documented by later processor manuals, when the inline =
assembler was written <g>. I'll see about adding it. In the meantime, =
you can get by with:

    db 0xDB, 0xE1

  "KarL" <someone somewhere.org> wrote in message =
news:b979vu$1nkh$1 digitaldaemon.com...
  Pinched the following code from somewhere:
#include <dos.h>////      Save FPU state.////      This uses a magic =
spell taken from Intel application note AP-113.//void fpusave (char far* =
t){    //_ES =3D FP_SEG (t);    //_BX =3D FP_OFF (t);    __asm les bx,t  =
  __asm  fnstcw  es:[bx]     // save IEM bit status    __asm  nop        =
         // delay while control word saved    __asm  fndisi              =
// disable BUSY signal    __asm  mov     ax, es:[bx] // get original =
control word in AX    __asm  fsave   es:[bx]     // save FPU state    =
__asm  fwait               // wait for save to complete    __asm  mov    =
 es:[bx],ax  // put original control word in saved state}////      =
Restore FPU state.//void fpurest (char far* t){    //_ES =3D FP_SEG (t); =
   //_BX =3D FP_OFF (t);    __asm les bx,t    __asm frstor es:[bx]}Found =
the compiler cannot recognise fndisi instruction.  Compiles with MS VC++ =
1.5 and above and BCC as well.

  When Obj2asmed the code generated by BC or VC,

  fndisi   (db e1)

  is being intepreted as

  fdisi    (9b db e1)

  Don't ask me what they mean as I haven't read into the Intel data book =
yet...
May 05 2003
parent "KarL" <someone somewhere.org> writes:
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I had a follow-up post on this already ....

Thanks Walter....

--------------8<------- Quote from the documentation-----------
Zortech C++ allowed instructions to be assembled from integers using the =
asm() pseudo-function.  For example:
asm (0x8C, 0x96, 0xCC, 0xFE);
DigiMars C++ does not provide this function. Therefore, you need to =
replace asm() calls with calls to __emit__.  For more information, see =
"Using Assembly Language Functions."
--------------8<------- Quote from the documentation-----------
  "Walter" <walter digitalmars.com> wrote in message =
news:b97k4c$2174$1 digitaldaemon.com...
  You're right. That instruction only does anything on the original =
8087, and isn't even documented by later processor manuals, when the =
inline assembler was written <g>. I'll see about adding it. In the =
meantime, you can get by with:
  =20
      db 0xDB, 0xE1
  =20
May 06 2003
prev sibling parent "Gisle Vanem" <giva users.sourceforge.net> writes:
"KarL" <someone somewhere.org> wrote:

 Found the compiler cannot recognise fndisi instruction.
Then why don't you use "fnsave" instead? --gv
May 06 2003