Can someone explain how the sqrt() function works internally? Thanks.
Printable View
Can someone explain how the sqrt() function works internally? Thanks.
asm VC++ sintax
Hum. I was having troubles when using 'num' instead of 'dword ptr [esp+4]' because the compiler was translating the num var adress as esp+8..... so I hard typed the adress every time.Code:__declspec(naked) float sqrt(float num){
__asm{
FLD dword ptr [esp+4]
FSQRT
FIST dword ptr [esp+4]
mov eax, dword ptr [esp+4]
ret
}
}
#include<stdio.h>
int main(){
float i;
for(i=0;i<20;i++)
printf("sqrt of %f is %f\n",i,sqrt(i));
return 0;
}
EDIT
actually if you debug the app and view the dissassembly, sqrt will call about 40 asm instrutions... don't ask me why...