# Square root function

Question asked by Manuel GM on Jan 14, 2010
Latest reply on Jan 14, 2010 by CompilerGuru

Hello again,

-I am targeting with MCF51EM256 CPU

-My version of CodeWarrior is: Codewarrior IDE version 5.9.0 Build 2830

Now I have done a square root function, but I have 3 error, maybe I must add any library?, the code is:

#define MAX_INT 5;

static long Acc_temp, Acc=0;

/**************************************************************************************************
* Función:     SquareRoot
* Argumentos:  ---
* Ambito:      Público
* ---------------------------------------------------------------------------------------------------
* parámetros de salida de 16 bits. (sin signo)
*****************************************************************************************************/
unsigned short SquareRoot(unsigned long A)
{
short j;
Acc = ASM_FF1(A);//Valor inicial
for(j=0;j<MAX_INT;j++)//Número de iteraciones máximo = 5
{
Acc_temp = (A/Acc + Acc)/2;//Cálcular iteración
if((abs(Acc - Acc_temp) < 0x0001)||(Acc_temp == 0))//Si el test de precisión es suficiente
break;//Salir del bucle si se alcanza una buena precisión
Acc = Acc_temp;//Guardar iteración previa
}
//Number_of_interactions[i] = (unsigned short) (j+1); // For debugging purposes
return((unsigned short)Acc_temp);
}

/**************************************************************************************************
* Función:     ASM_FF1
* Argumentos:  ---
* Ambito:      Público
* ---------------------------------------------------------------------------------------------------
* Descripción: Función para obtener el primer elemento de la iteración (seed). Parámetros de entrada
* de 32 bits, parámetros de salida de 16 bits. (sin signo)
*****************************************************************************************************/
unsigned long ASM_FF1(unsigned long A)
{
asm(ff1.l d0);//Obtener el primer elemento
A= (32-A)>>1;//Dividir por dos el primer índice
A = (unsigned long)1<<A;//Multiplicar por dos
return(A);
}

and errors:

Error   : expression syntax error
ADE7753.c line 581     for(j=0;j<MAX_INT;j++)//Número de iteraciones máximo = 5

Error   : expression syntax error

Error   : ';' expected

Thanks!

Best regards

Fernin