将代码从c转换为assemly

时间:2018-04-18 19:24:59

标签: c assembly

我无法正确地将c代码转换为汇编代码

代码是

    #include <stdio.h>      /* Standard Library of Input and Output */
   #include <complex.h>    /* Standard Library of Complex Numbers */


 double complex power(double complex value, int power){
     double complex result=1;
    for (int i=0;i<power;i++){
        result  = result * value;
    }
    return result;
 }

  double complex function(double order,double complex * array,double complex value) // a function that calculates f(x)
  {
    double complex result=0;
     for (int i = order ; i >= 0 ; i--){
      result = result + array[i]*(power(value,i));
  }
   //printf("the value of f(x) is:  = %.10f %+.10fi\n",creal(result), cimag(result));
  return result;
 } 
double complex derivefunction(double order,double complex * array,double complex value,double complex * darray){
  for (int i = order-1 ; i >= 0 ; i--){
       darray[i] = array[i+1]*(i+1);
}
return function(order-1,darray,value);

  }
   double abs(double m){//absolute
    if (m<0) 
        return -m;
    return m;
  }

  int main(void) {


   double tol,order;
   double arrayr[100];//assuming the maximum order is 0
   double arrayi[100];
   double complex array[100];

    printf("Enter the tolarence:\n");
    scanf("%lf", &tol);
    printf("the toleracnce is: %.10f\n",tol);


printf("Enter the order\n");
scanf("%lf", &order);
printf("the order is: %lf\n",order);


for (int i = order ; i >= 0 ; i--){
    printf("Enter the %d coeficience\n",i);
    scanf("%lf", &(arrayr[i]));//taking the real number
    scanf("%lf", &(arrayi[i]));// taking the imaginary number
    array[i] = arrayr[i] + arrayi[i] * I;//summing the complex number
    printf("The %d coeficience is  = %.2f %+.2fi\n",i ,creal(array[i]), cimag(array[i]));
}


double initialr, initiali;
double complex initial;
printf("Enter the initial value of z(the guss) \n");
scanf("%lf", &initialr);//taking the real number
scanf("%lf", &initiali);// taking the imaginary number
initial = initialr + initiali*I;

printf("The initial is  = %.2f %+.2fi\n", creal(initial), cimag(initial));
double complex result1 = function(order,array,initial);



     if (order > 0) {

    double complex darray[sizeof(array)];
    double complex result2 = derivefunction(order,array,initial,darray);



    //now the newton-rashford method
      double complex m = result1/result2;//the initial
    while (abs((double)(m)) >= tol)//if it is in the range
  {

        m = function(order,array,initial) / derivefunction(order,array,initial,darray);//f(x)/f'(x)
        initial = initial - m;
        //printf("The initial is  = %.10f %+.10fi\n", creal(initial), cimag(initial));
  }
  printf("The root is  = %.10f %+.10fi\n", creal(initial), cimag(initial));
 }

return 0;

  }

我使用命令gcc -S -O main.c来创建一个名为main.s的汇编文件 但是当我尝试编译汇编文件时,我得到了很多错误

    nasm -g -f elf64 -w+all -o main.o main.s
    main.s:1: error: attempt to define a local label before any non-local labels
    main.s:1: error: parser: instruction expected
    main.s:2: error: attempt to define a local label before any non-local labels

依旧等等。我认为这与我使用复数这个事实有关,但我不知道如何解决这个问题。

0 个答案:

没有答案