Hi !

I am a programming assembler beginner and i have never implemented an Assembler program in VC++.
Recently i found a program which i assume to be an assembler function. I'd like to test this function in VC++ but i absolutly don't know how to use an assembler code in VC++. It would be great if somebody would show me a way to make this prog run in VC++.
Thank you ! :confused:


code:

--------------------------------------------------------------------------------------------------------------

;extern "C" long double _cdecl exp (double x)
_asm
{
_exp PROC NEAR
PUBLIC _exp
FLDL2E
FLD QWORD PTR ; x
FMUL ; z = x*log2(e)
FIST DWORD PTR ; round(z)
SUB ESP, 12
MOV DWORD PTR , 0
MOV DWORD PTR , 80000000H
FISUB DWORD PTR ; z - round(z)
MOV EAX,
ADD EAX,3FFFH
MOV ,EAX
JLE SHORT UNDERFLOW
CMP EAX,8000H
JGE SHORT OVERFLOW
F2XM1
FLD1
FADD ; 2^(z-round(z))
FLD TBYTE PTR ; 2^(round(z))
ADD ESP,12
FMUL ; 2^z = e^x
RET

UNDERFLOW:
FSTP ST
FLDZ ; return 0
ADD ESP,12
RET

OVERFLOW:
PUSH 07F800000H ; +infinity
FSTP ST
FLD DWORD PTR ; return infinity
ADD ESP,16
RET

_exp ENDP

-----------------------------------------------------------------------------------------------------------------------------------
:confused:
Posted on 2003-05-02 05:03:26 by jack37a
Try this.

[size=12]__declspec(naked) long double _cdecl exp( double x )

{
__asm
{
fldl2e
fld qword ptr [esp+4] // x
fmul // z = x*log2(e)
fist dword ptr [esp+4] // round(z)
sub esp, 12
mov dword ptr [esp], 0
mov dword ptr [esp+4], 0x80000000
fisub dword ptr [esp+16] // z - round(z)
mov eax, [esp+16]
add eax, 0x3fff
mov [esp+8], eax
jle UNDERFLOW
cmp eax, 0x8000
jge OVERFLOW
f2xm1
fld1
fadd // 2^(z-round(z))
fld tbyte ptr [esp] // 2^(round(z))
add esp, 12
fmul // 2^z = e^x
ret

UNDERFLOW:
fstp st
fldz // return 0
add esp, 12
ret

OVERFLOW:
push 0x7F800000 // +infinity
fstp st
fld dword ptr [esp] // return infinity
add esp, 16
ret
}
}[/size]
Posted on 2003-05-02 09:59:37 by iblis
HI !

thanks, i tried that and the compiler complains about dword and qword. Maybe I have to include some windows header files but which one. Does anybody have an assembler VC++ tutorial for me ?
Posted on 2003-05-02 16:32:46 by jack37a
The Function works in VC++ but the inline compiler complains about

error C2400: Inline-Assembler: Syntaxfehler in 'Erster Operand'; 'constant' gefunden

JLE SHORT UNDERFLOW

error C2400: Inline-Assembler: Syntaxfehler in 'Erster Operand'; 'constant' gefunden

JGE SHORT OVERFLOW

error C2400: Inline-Assembler: Syntaxfehler in 'Opcode'; 'constant' gefunden

UNDERFLOW:
FSTP ST
FLDZ //; return 0
ADD ESP,12
RET

error C2400: Inline-Assembler: Syntaxfehler in 'Opcode'; 'constant' gefunden

OVERFLOW:
PUSH 07F800000H //; +infinity
FSTP ST
FLD DWORD PTR //; return infinity
ADD ESP,16
RET

Who can help me ?
Posted on 2003-05-06 17:55:08 by jack37a
what vc++ version are you using?
Posted on 2003-05-06 19:57:15 by arkane
I tried it and it compiled fine.
Posted on 2003-05-06 22:46:47 by iblis
Thanks to all !

It works ! And the function is extremly fast ....
My mistake was that i had a second function and i had included MATH.h in my program.
Without Math.h it compiled fine .....

Thanks again !
Posted on 2003-05-07 05:30:42 by jack37a
Hi !

Can I export this function as an C Objectfile (*.obj) or is an assembler function C++ specific.
If it is possibe, how do I do it ?

Thanks !
Posted on 2003-05-09 04:37:26 by jack37a