Monday, May 4, 2009

 

Using FLDPI and FMUL instructions

The FLDPI and FMUL instructions can be used in conjunction with FSIN to generate an accurate result for SIN (PI/2). The FLDPI will load PI in ST0. We can then use FMUL to multiply ST0 with 0.5 to generate PI/2 in ST0. FSIN then computes Sin (PI/2).

Note: Instead of FMUL with an operand of 0.5, you can also use FDIV with an operand of 2.0


------------------------------------------------------------
section .data
data dd 0.5

section .text
global _start
_start:
nop
finit
fldpi ; load PI in ST0
fmul dword [data]
fsin
------------------------------------------------------------
GDB:

10 fldpi ; load PI in ST0
1: $st0 = 0

11 fmul dword [data]
1: $st0 = 3.1415926535897932385128089594061862 ---> PI

12 fsin
1: $st0 = 1.5707963267948966192564044797030931 ---> PI/2

14 mov eax,1
1: $st0 = 1 ---> Sin (PI/2)
------------------------------------------------------------

Comments:
Nice tips, dude. Waiting for more x86/x87 tips and tricks.
 

Post a Comment

Subscribe to Post Comments [Atom]





<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]