section .text use32 global _sqr _sqr: push ebp mov ebp,esp fld qword [ebp+08h] fmul to st0 pop ebp retassuming that we have saved this code in file fpu.asm, we can compile it using NASM as follows
nasm -f coff fp u.asm (in cygwin)
nasm -f elf fpu.asm (in linux)
this was the first part.. the second is to create code in c++ using our external sqr function, for example:
#include <stdio.h>
extern "C"
{
cpx tst1( const cpx c );
}
int main()
{
double d = 2.0;
printf("%f %f",d,sqr(d));
return 0;
}
to compile this code using g++ compiler we need to pass previously compiled assembler code to the linker.
g++ fpu.o tst.cpp