简体   繁体   English

C内联汇编x86 fbstp指令

[英]C inline assembly of x86 fbstp instruction

Was wondering how to inline a usage of fbstp on a 32 bit I86 architecture. 想知道如何在32位I86架构上内联使用fbstp。 I tried something like 我试过类似的东西

int main( )
{
    double foo = 100.0;

    long bar = 0;

    asm( "pushl %1; fbstp %0"
         : "=m"(bar)
         : "r"(foo)
       );

    ...

But bar is unchanged. 但是酒吧没有变化。 I have tried reading everything I can find on this but most example simply do things like add two integers together. 我已经尝试过阅读我能找到的所有内容,但大多数例子只是做一些事情,比如将两个整数加在一起。 I can't find any that talk about pushing operands onto the stack and what I should be doing when an instruction like fbstp writes 80 bits of data back to memory ( ie what C type to use ) and how to specify it in the asm syntax. 我找不到任何关于将操作数推入堆栈的讨论以及当fbstp等指令将80位数据写回内存(即使用什么C类型)以及如何在asm语法中指定它时我应该做什么。

Also on x86-64 there seems to be a pushq and no pushl but fbstp still exists whereas fbstq does not. 同样在x86-64上似乎有pushq而没有pushl但是fbstp仍然存在而fbstq没有。 Is there some other magic for 64 bit. 64位还有其他一些魔力吗?

There's an example here: http://bap.ece.cmu.edu/download/bap-0.1/VEX/test/test-i386.c 这里有一个例子: http//bap.ece.cmu.edu/download/bap-0.1/VEX/test/test-i386.c

which seems to suggest doing something like this: 这似乎建议做这样的事情:

unsigned short bcd[5];
double a;

asm("fbstp %0" : "=m" (bcd[0]) : "t" (a) : "st");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM