This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

x87 register clobber returns "unknown register name" error


Hello,

I am trying to write inline assembly code that uses the x86 floating
point stack.

As far as I understood
https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Clobbers , the
proper register clobber to use in this case is "st(x)". For example,
this example from the documentation uses the "st(1)" clobber :

asm ("fyl2xp1" : "=t" (result) : "0" (x), "u" (y) : "st(1)");

However, if I try it on the trivial example attached, it fails with the
following error.

$ gcc-4.8 display_representation.c
display_representation.c: In function âmainâ:
display_representation.c:11:5: error: unknown register name âst(0)â in âasmâ
     asm volatile ("fstps (%1)" :
     ^

What am I doing wrong ?

Thanks in advance,
Hadrien Grasland
#include <stdint.h>
#include <stdio.h>

int main()
{
    float input = 1.0f;
    uint8_t output[sizeof(input)];
    int i;
    
    // Copy input's internal representation to output
    asm volatile ("fstps (%1)" :
                  : // No output
                  "t" (input), "r" (output) :
                  "memory", "st(0)");
    
    // Display the input's representation
    printf("Internal float representation : ");
    for (i = 0; i < sizeof(output); ++i)
    {
        printf("%02hhX ", output[i]);
    }
    printf("\n");
    
    return 0;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]