ASSEMBLY LANGUAGE The matrix twodimensional array with ROWS
ASSEMBLY LANGUAGE
The matrix (two-dimensional array) with ROWS and COLS dimensions of integer values is given. Perform various matrix processing activities according to the algorithms below. Store the results into the output vector (one-dimensional array) with appropriate size.
For Grade 7) Count the number of odd values (n mod 2 <> 0) for each row.
For Grade 9) Calculate the sum of positive values for each column.
To obtain inputs and return the results, define appropriate type C/C++ functions. Please use the following template as a base for solution:
#include \"stdafx.h\"
#include <cstdio>
#include <cassert>
// For each grade level variant implement own function, e.g.:
void solution_for_grade_X(const int * arr, size_t arr_rows, size_t arr_cols, int * result)
{
__asm
{
// Your Inline Assembler instructions for grade X level go here
// :::
}
}
const int ROWS = 2;
const int COLS = 3;
int main()
{
// Change the array definitions to be appropriate for your assignments:
int data1[ROWS][COLS] = { { 0, -1, 2 }, { 3, 4, -5 } };
int result1[ROWS]; // Note: for some assignments the result size will depend on the COLS!
// Change the parameters according to your assignment function, e.g.:
solution_for_grade_X((const int *)data1, ROWS, COLS, result1);
// Print the result one-dimensional array to the console:
for (size_t i = 0; i < ROWS; i++)
printf(\"%d \", res1[i]);
// :::
return 0;
}
Solution
#include <iostream>
#include <cstdio>
#include <cassert>
using namespace std;
// For Grade 7) Count the number of odd values (n mod 2 <> 0) for each row
void solution_for_grade_7(const int * arr, size_t arr_rows, size_t arr_cols, int * result)
{
for(int i = 0 ; i < arr_rows ; i ++){
int numOdVals = 0;
for(int j = 0; j < arr_cols ; j++){
if( ((*arr)%2) != 0){
numOdVals++;
}
arr++;
}
(*result) = numOdVals;
result++;
}
}
//For Grade 9) Calculate the sum of positive values for each column.
void solution_for_grade_9(const int * arr, size_t arr_rows, size_t arr_cols, int * result)
{
for(int i = 0 ; i < arr_rows ; i ++){
int numOdVals = 0;
for(int j = 0; j < arr_cols ; j++){
if(*arr > 0){
*(result+j) = *(result+j) + *arr;
}
arr++;
}
}
}
//Number of rows
const int ROWS = 2;
//Rows of columns
const int COLS = 3;
int main(int argc, char *argv[])
{
// Change the array definitions to be appropriate for your assignments:
int data1[ROWS][COLS] = { { 0, -1, 2 }, { 3, 4, -5 } };
int result1[ROWS]; // Note: for some assignments the result size will depend on the COLS!
// Change the parameters according to your assignment function, e.g.:
solution_for_grade_7((const int *)data1, ROWS, COLS, result1);
// Print the result one-dimensional array to the console:
for (size_t i = 0; i < ROWS; i++)
printf(\"%d \", result1[i]);
// /For Grade 9) Calculate the sum of positive values for each column.
int result2[COLS] = {0};
solution_for_grade_9((const int *)data1, ROWS, COLS, result2);
// Print the result one-dimensional array to the console:
for (size_t i = 0; i < COLS; i++)
printf(\"%d \", result2[i]);
return 0;
}


