Question
Could someone convert this C++ code into MARS MIPS assembly code? ------------------------------------------------------------------------------------------- #include const int MAX = 100; void dispMat(int A[][MAX], int rows, int cols)
Could someone convert this C++ code into MARS MIPS assembly code?
-------------------------------------------------------------------------------------------
#include
const int MAX = 100;
void dispMat(int A[][MAX], int rows, int cols)
{
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++){
printf("%d ", A[i][j]);
printf(" ");
} }
}
void mulMatVec(int r1, int c1, int A[][MAX],
int r2, int c2, int V[][MAX])
{
int i, j, k;
int Z[MAX][MAX];
if (r2 != c1) {
printf("Invalid Input: Matrix multiplication not possible ");
return;
}
for (i = 0; i < r1; i++) {
for (j = 0; j < c2; j++) {
Z[i][j] = 0;
for (k = 0; k < r2; k++)
Z[i][j] += A[i][k] * V[k][j];
}
}
printf(" Below is the result matrix: ");
dispMat(Z, r1, c2);
}
int main()
{
int r1, c1, r2, c2, i, j;
int A[MAX][MAX], V[MAX][MAX];
printf(" First Matrix Rows: ");
scanf("%d", &r1);
printf("%d", r1);
printf(" First Matrix Column: ");
scanf("%d", &c1);
printf("%d", c1);
printf(" First Matrix Elements: ");
for (i = 0; i < r1; i++) {
for (j = 0; j < c1; j++) {
printf(" A[%d][%d]: ", i, j);
scanf("%d", &A[i][j]);
printf("%d", A[i][j]);
}
}
printf(" Second Matrix Rows: ");
scanf("%d", &r2);
printf("%d", r2);
printf(" Second Matrix Columns: ");
scanf("%d", &c2);
printf("%d", c2);
printf(" Second Matrix Elements: ");
for (i = 0; i < r2; i++) {
for (j = 0; j < c2; j++) {
printf(" V[%d][%d]: ", i, j);
scanf("%d", &B[i][j]);
printf("%d", B[i][j]);
}
}
printf(" First Matrix: ");
dispMat(A, r1, c1);
printf(" Second Matrix: ");
dispMat(V, row2, col2);
mulMatVec(r1, c1, A, r2, c2, V);
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started