Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using FSINCOS

Status
Not open for further replies.

kismetlafiete

Programmer
Oct 13, 2004
8
US
For my midterm project our instructor gave us a graphical program in qbasic that he wants us to translate into assembly. I've got pretty much everything figured out, how to initialize graphics mode and how to put a pixel where I want it. What I need now is some way to find the sine of certain numbers(sin(number) ). I did some research and found the instruction FSINCOS (op code D9FB) and eventually I found this description of it:

Computes both the sine and the cosine of the source operand in register ST(0), stores the sine in ST(0), and pushes the cosine onto the top of the FPU register stack. (This instruction is faster than executing the FSIN and FCOS instructions in succession.)


So, I assume that has something to do with the stack which we haven't learned yet.( what is ST(0)?) Just wondering if someone out there that knows how could give me a sample code snippet just showing how to use the instruction. I'm going to read up on using the stack right now, but an example of how to use this instruction would be wonderful.

Just for some background, the whole class is me and another guy(senior-level elective course in college), so I can't really ask my "other classmates" for help, as we're supposed to do this together and neither of us has any idea. The guidance our professor gave us was "read your book" (no help there either really). We're using NASM, also.
 
Hey kis,


The instructions you are trying to use are running in a separate part of the processor, that is called floating point coprocessor, or math coprocessor.

The results of the floating point instructions are stored in registers of the fp coprocessor. Those registers behave like a stack, so ST(0) is register 0 on the intel x86 math coprocessor,

regards,

Rick
 
You could look up online a "sine table generator" and use that instead? It'd be fast and easy, too.
 
Seth is right, a sine table is easier, but if you want to use that instruction, you have to start de fp processor, i do not have used that particular instruction, but here is a brief example that calculates tangent:

mov esi, 0 ; init index register
mov cx, 46 ; it will calculate 46 values
finit ; init coprocesador

more: fldpi ; loads pi on stack
fild radian ; loads radian 180
fdiv
fild angle ; loads angle
fmul
fptan ; calculates tangent
fdiv ; real tan
fstp ttable[esi] ; pops out value in table
fld ttable[esi]
add esi, 08d
loop more
fwait

(note: angle, radian, ttable are user defined variables)

regards,

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top