Article ID: 117682
Article Last Modified on 10/14/2003
rem MAKEFTST.BAT
rem Batch program to build the test files
cl /c /AL /Od /Zi floatstc.c
ml /c /FPi /Zi floatsta.asm
rem /FPi allows the MASM module to use the C floating point emulator
link /CO floatstc + floatsta;
rem Resulting program is FLOATSTC.EXE and can be test in CodeView
rem if desired
;assembly language routines
.MODEL LARGE,C
.8087
PUBLIC Add1
PUBLIC Add1Again
.FARDATA
temp REAL4 ? ; temporary storage for return value
.CODE
; procedure to return a float
Add1 PROC USES es, y:REAL4
; y is the float passed from C
ASSUME ES:SEG temp
mov ax, SEG temp
mov es, ax ; load the far data segment
fld DWORD PTR y ; load the coprocessor
fld1
faddp ST(1),ST ; add 1 to the value passed in
fstp DWORD PTR es:temp ; store the value to temporary storage
mov dx, SEG temp ; load DX:AX with the address of temp
mov ax, OFFSET temp
; this is what the C module expects as a return value
ret
Add1 ENDP
; procedure to do the same things
; but return a value at the passed address
Add1Again PROC USES es bx, y:REAL4, z:DWORD
; y is the float passed from C
;z is the address of a float in the C module
ASSUME ES:NOTHING
les bx, z ; load ES:BX with the address of the return location
fld DWORD PTR y
fld1
faddp st(1),st
fstp DWORD PTR es:[bx]
; store the final value to the C modules data area
ret
Add1Again ENDP
END
/****************************************
* C module to test the assembly routines
****************************************/
#include <stdio.h>
float Add1(float i);
void Add1Again(float i, float *j);
float p = 10;
float y = 0;
float z = 0;
void main()
{
y = Add1(p);
printf("p = %f\t\ty = %f\n",p,y);
Add1Again(p, &z);
printf("p = %f\t\tz = %f\n",p,z);
}
86081 PRB: DLL Function Returns Float or Double Value Incorrectly
Additional query words: kbinf 6.00 6.00a 6.10 6.10a s_c
Keywords: KB117682