Return a float from a 64-bit assembly function that uses x87 FPU
<p>I am trying to make a program that calculates equations (what equation doesn't matter currently) that use 64-bit registers, floats, and coprocessor instructions. Unfortunately I don't know how to access the final outcome of the equation as a float. I can do:</p>

<pre><code>fist qword ptr [bla]
mov rax,bla
</code></pre>

<p>and change the function type to <em>INT</em> and get my value, but I cannot access it as a FLOAT. Even when I leave the result in ST(0) (the top of the coprocessor stack) it doesn't work as expected and my <em>C++</em> program gets the wrong result. My assembly code is:</p>

<pre><code>public funct
.data
bla qword ?
bla2 qword 10.0
.code
funct PROC
push rbp
mov rbp, rsp
push rbx

mov bla,rcx
fild qword ptr[bla]

fld qword ptr [bla2]
fmul st(0), st(1)
fist dword ptr [bla]
pop rbx
pop rbp
ret
funct ENDP
END
</code></pre>

<p>My <em>C++</em> code is:</p>

<pre><code>#include &lt;stdlib.h&gt;
#include &lt;cstdlib&gt;
#include &lt;stdio.h&gt;

extern "C" float funct(long long n);
int main(){

    float value1= funct(3);

    return 0;
}
</code></pre>

<p>What is the problem, and how can I fix it?</p>