Question: Given the matrix multiplication code matrix.c below, please convert the loop body of the nested for - loop into the corresponding inline assembly version. Original

Given the matrix multiplication code matrix.c below, please convert the loop body of the nested for-loop
into the corresponding inline assembly version.
Original C Code:
/*
* description: matrix - multiply benchmarking
*
*|h11 h12 h13||x1 x2||y1 y2|| h11*x1+h12*x3+h13*x5 h11*x2+h12*x4+h13*x6|
*|h21 h22 h23|*|x3 x4|=|y3 y4|=| h21*x1+h22*x3+h23*x5 h21*x2+h22*x4+h23*x6|
*|h31 h32 h33||x5 x6||y5 y6|| h31*x1+h32*x5+h33*x5 h31*x2+h32*x4+h33*x6|
*
* Element are to store in following order:
*
* matrix h[9]={h11,h12,h13, h21,h22,h23, h31,h32,h33}
* vector x[6]={x1,x2, x3,x4, x5,x6}
* vector y[6]={y1,y2, y3,y4, y5,y6}
*/
#include
int main()
{
int f,i,j;
int h[9]={0}, x[6]={0}, y[6]={0};
for(i =0; i <9; i++) scanf("%d", &h[i]);
for(i =0; i <6; i++) scanf("%d", &x[i]);
for(i =0; i <6; i++) scanf("%d", &y[i]);
int *p_x = &x[0];
int *p_h = &h[0];
int *p_y = &y[0];
for (i =0; i <3; i++){
/* p_x points to the beginning of the input vector */
p_x = &x[0];
NCKU_Computer_Organization_2024_Assignment_1.md 2024-03-26
10/14
/* do matrix multiply */
for (j =0; j <2; j++){
p_h = &h[i *3];
for (f =0; f <3; f++)
*p_y +=*p_h++**p_x++;
*p_x++;
/* next element */
p_x = &x[1];
p_y++;
}
}
return 0;
}
Please modify the above c code to inline assembly version. You should copy the following code and write your
code in asm volatile(). Beware Your Code is in the for loop.
#include
int main()
{
int f, i, j;
int h[9]={0}, x[6]={0}, y[6]={0};
FILE *input = fopen("../input/3.txt","r");
for(i =0; i <9; i++) fscanf(input,"%d", &h[i]);
for(i =0; i <6; i++) fscanf(input,"%d", &x[i]);
for(i =0; i <6; i++) fscanf(input,"%d", &y[i]);
fclose(input);
int *p_x = &x[0];
int *p_h = &h[0];
int *p_y = &y[0];
for (i =0; i <3; i++){
for (j =0; j <2; j++){
for (f =0; f <3; f++){
asm volatile(/*Your Code*/);
}
}
}
p_y = &y[0];
for(i =0; i <6; i++) printf("%d ",*p_y++);
printf("
");
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!