2

if i use fsin to find the sin value of real number. im find and expression syntax error. i#m using turbo c++ 3.0 on dos.

i have looked for the instruction listing in x87 fpu. i tried to google some information. and also changed my intruction set reference on compiler setting from 8087 to 80287.

 #include<stdio.h>
    #include<math.h>

void main(){
    double a = 1.98,val;
    asm{
    fld a
    fsin
    fstp val
    }
    printf("%f", val);
}

expression sntax error: fsin

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Madhu
  • 55
  • 1
  • 5

1 Answers1

5

fsin, fcos, and fsincos instructions were not available until the 80387. Your compiler is unaware of these instructions in the version of Turbo-C++ you are using. If you are running your program in an environment that emulates an 80387 or has a physical 80387 present then you can consider encoding the fsin instruction with a db directive. According to the Instruction Set Architecture reference The fsin instruction is encoded as D9 FE. Your code could look like:

#include<stdio.h>
#include<math.h>

void main(){
    double a = 1.98,val;
    asm{
        fld a
        db 0d9h, 0feh
        fstp val
    }
    printf("%f", val);
}

Note: This code will not function correctly on a system with no FPU, nor will it run on a system with an 8087 or 80287 FPU.


The 80387 Programmers Reference Manual 1987 has a compatibility table for the 8087, 80287, and 80387 processors that describes the supported functionality for this processor family:

enter image description here

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
  • Nope. but may be i have to use TASM. but however can compile inline assembly code using TASM – Madhu Aug 13 '19 at 19:15
  • @Mahdu. You say you are using Turbo-C++ 3. Are you saying the code snippet in this answer didn't work? (The one that replaces `fsin` with `db 0d9h, 0feh`). If so, what did it do? Did it fail to compile/link? Did it run but not display the right number? I have Turbo-C++ 3.0 here and it does work. My opinion is the only way it would fail would be that what you ran it on doesn't have a proper CPU. As for why TASM works, I'd bet you because the version (what version are you using) supports the `.387` directive and can encode `fsin`. – Michael Petch Aug 13 '19 at 19:19
  • @Madhu on top of my other question in my last comment what version of TASM are you using? – Michael Petch Aug 13 '19 at 19:21
  • sorry its solved now. its working with what ever information you give. thank you so much for the help. – Madhu Aug 15 '19 at 16:01
  • @madhu : glad you got it going. If this solution solved your question please consider accepting it as an answer to mark it solved for future readers. More on the hows and whys of accepting an answer can be found here: https://meta.stackexchange.com/a/5235/271768 – Michael Petch Aug 22 '19 at 03:15