Inline Assembly Intro - Float Point Register Usage

来源:互联网 发布:盘搜搜引擎源码 编辑:程序博客网 时间:2024/05/16 01:33




/* areatest.c - An example of using floating point regs */
#include <stdio.h>
int main()
{
 int radius = 10;
 float area;
 asm(“fild %1\n\t”
 “fimul %1\n\t”
 “fldpi\n\t”
 “fmul %%st(1), %%st(0)”
 : “=t”(area)
 :”m”(radius)
 : “%st(1)”);
 printf(“The result is %f\n”, area);
 return 0;
}

The areatest.c program places the radius value into
a memory location, and then loads that value into
the top of the FPU stack with the FILD instruction.
That value is multiplied by itself, with the result
still in the ST(0) register. The pi value is then
placed on top of the FPU stack, shifting the squared
radius value down to the ST(1) position. The FMUL
instruction is then used to multiply the two values
within the FPU.
The output value is taken from the top of the FPU
stack and assigned to the area C variable. Because
the ST(1) register was used, but not assigned as an
output value, it must be listed in the changed
registers list so the compiler knows to clean it up
afterward.


0 0
原创粉丝点击