# An example of using the FSIN and FCOS instructions
#
# 三角函数
#
# radians = (degrees * pi) / 180
#
# fsts degree1 # load the degrees value stored in memory into ST0
# fidivs val180 # divide by the 180 value stored in memory
# fldpi # load pi into ST0, degree/180 now in ST1
# fmul %st(1), %st(0) # multiply degree/180 and pi, saving in ST0
# fsin # perform trig function on value in ST0
#
# 在产品型的程序中,预先计算pi/180的值并且把它存储在FPU中显然要快得多,而不是每次都计算这个值
#
.section .data
degree1:
.float 90.0
val180:
.int 180
.section .bss
.lcomm radian1, 4
.lcomm result1, 4
.lcomm result2, 4
.section .text
.globl main
main:
nop
finit
flds degree1
fidivs val180
fldpi
fmul %st(1), %st(0)
fsts radian1
fsin
fsts result1
flds radian1
flds radian1
fcos
fsts result2
movl $1, %eax
movl $0, %ebx
int $0x80
# gcc -g -o 08 08-fsin-fcos.s -m32
#
# st0 -4.37113900018644366547e-08 (raw 0xbfe6bbbd2e7b967fef2c)
#