KlaudiaWi
KlaudiaWi

Reputation: 21

Returning float value from Assembler DLL to C++ using SSE

I have got a problem with returning a float value from DLL Assembler to C++ program. I suppose that it should be handled in xmm0 register, am I wrong? Here is main file:

#include "stdafx.h"
#include<windows.h>
#include<iostream>
#include <cstdio>
#include <thread>
#include <vector>
using namespace std;

extern "C" float _stdcall MyProc1(float begin, float end, float x2 ,float x1, float x0);    //dll assembler

int main(int argc, _TCHAR* argv[])
{
    float suma=0;
    suma = MyProc1(12.75,9.3,0,0,1);
    cout << std::hex<< suma << endl;
    getchar();
    return 0;
}

and here is my Assembler DLL:

.686p
.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE
INCLUDE C:\masm32\include\windows.inc
.mmx
.xmm

.DATA
    pi dd 3.14159265358979 ; constant

.CODE

DllEntry PROC hInstDLL:HINSTANCE, reason:DWORD, reserved1:DWORD
    mov eax, TRUE 
    ret 
DllEntry ENDP


MyProc1 proc b:DWORD, e:DWORD, x2: DWORD, x1: DWORD, x0:DWORD 

    movss xmm0,[b]  
    ret

MyProc1 endp    

END DllEntry 

and the return value is -1.#IND, why?

Upvotes: 2

Views: 948

Answers (1)

IanM_Matrix1
IanM_Matrix1

Reputation: 1594

This is very compiler specific, but I'd guess you're using a 32 bit Microsoft compiler.

In this case, as you've defined your function to return a float, you need the result to be placed at the top of the floating point stack.

Check the assembly output of your C++ code to check for certain - you should see an fst or fstp instruction after the function call.

Upvotes: 1

Related Questions