Can you help me write an assembler box right in the cycle?
-
I tried to write a box but it didn't work. The commentary points out what the box should do.
#include<stdio.h> #include<math.h> #include<locale.h> #include<malloc.h> #include<stdlib.h>
int main()
{
setlocale (0, "");
double x, mo, s;
int n, i;double *X = &x;
double *MO = &mo;
double *S = &s;
int *N = &n;
int *I = &i;printf("Vvedite kolichestvo chisel v massive \n");
printf("n:");
if (scanf("%d", &n))
{
double a[n];
double *A = &a[i];
mo=0;
printf("Vvedite znacheniya elementov \n");
for (i = 0; i<n; i++)
{
printf("a[%d] = ", i);
if (!(scanf("%lf", &a[i])))
{
printf("Error. Vvedeni nepravelnie dannie\n");
break;
}else { //mo=mo+a[i]; asm ( ".intel_syntax noprefix \n\t" "mov ax, [%1] \n\t" "mov bx, [%2] \n\t" "add ax, bx \n\t" "mov [%0], ax \n\t" : "=r"(MO) : "r"(MO), "r"(A[I]) : "%ax", "%bx" ); if (i==(n-1)) { printf("Mat ogidanie: %lf\n", mo); s=mo/n; printf("Srednekvadratichnoe otklonenie: %lf\n", s); } }
}
}
else printf("Error. Vvedeni nepravelnie dannie\n");
return 0;
}
-
In your case, there are two options.
First
For
double
Usefloat
and use the co-processor's team peacefully x87:__asm__( "FLDS %1 \n" // mo "FADDS %2 \n" // mo + a[i] "FSTPS %0 \n" // mo : "=m"(mo) : "m"(mo), "m"(a[i]) : );
Second
Use a set of SSE instructions, which is much more painful. I don't recommend doing this through the ass box, you can just go through the sie.