Question

ASSEMBLY LANGUAGE The matrix (two-dimensional array) with ROWS and COLS dimensions of integer values is given....

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;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#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;
}

Add a comment
Know the answer?
Add Answer to:
ASSEMBLY LANGUAGE The matrix (two-dimensional array) with ROWS and COLS dimensions of integer values is given....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • i created a two dimensional matrix class which holds my object complex number. I am trying...

    i created a two dimensional matrix class which holds my object complex number. I am trying to overload the parenthesis () so that I can access and modify the value at specified location of the matrix. say matrix[a][b] = 5; and my_vals is a private member of the matrix class. What is the problem with my code //constructor & inlitilize dynamic array matrix::matrix(int rows, int cols) { complex** m_vals = new complex * [rows]; for (int i = 0; i...

  • I need help modifying this program. How would I make sure that the methods is being...

    I need help modifying this program. How would I make sure that the methods is being called and checked in my main method? Here is what the program needs to run as: GDVEGTA GVCEKST The LCS has length 4 The LCS is GVET This is the error that I'm getting: The LCS has length 4 // I got this right The LCS is   //the backtrace is not being called for some reason c++ code: the cpp class: /** * calculate...

  • How to initialize a dynamic two-dimensional array with values? (C++) Here's my problem... # include using...

    How to initialize a dynamic two-dimensional array with values? (C++) Here's my problem... # include using namespace std; int main() {    // Q#5 - dynamic 2d arrays, indexing via subscript operator, pointer arithmetic    // tic tac toe board is an array of int pointers    // each int pointer in the board points to a row    // declare a pointer to an array of int pointers (i.e. a pointer to a pointer of type int)    const...

  • Need C++ coding for this lab exercise given below :) 4. Lab Exercise — Templates Exercise...

    Need C++ coding for this lab exercise given below :) 4. Lab Exercise — Templates Exercise 1 - Function Templating For this part of the lab make a template out of the myMax function and test it on different data types. Copy maxTemplate.cpp to your Hercules account space. Do that by: Entering the command:cp /net/data/ftp/pub/class/115/ftp/cpp/Templates/maxTemplate.cpp maxTemplate.cpp Compile and run the program to see how it works. Make a template out of myMax. Don't forget the return type. Modify the prototype appropriately. Test your myMax template on int, double,...

  • QUESTION 25 Examine the following program segment. Assuming the array table has values in it, what...

    QUESTION 25 Examine the following program segment. Assuming the array table has values in it, what is the correct outcome? double table [10] [2], sum=0.0; int i, j, nrows=10; for(i=0; i<=nrows-1; i++) sum += tableta (3); It will sum the table values in the rows only. It will sum the table values in the columns only. It will not sum the table values because nrows is too small. It will not sum the table values because the columns are not...

  • Concepts tested by the program: Working with one dimensional parallel arrays Use of functions Use of...

    Concepts tested by the program: Working with one dimensional parallel arrays Use of functions Use of loops and conditional statements Description The Lo Shu Magic Square is a grid with 3 rows and 3 columns shown below. The Lo Shu Magic Square has the following properties: The grid contains the numbers 1 – 9 exactly The sum of each row, each column and each diagonal all add up to the same number. s is shown below: Write a program that...

  • Write a c++ program: Many mathematical problems require the addition, subtraction, and multiplication of two matrices. Write an ADT Matrix. You may use the following class definition: const int MAX_RO...

    Write a c++ program: Many mathematical problems require the addition, subtraction, and multiplication of two matrices. Write an ADT Matrix. You may use the following class definition: const int MAX_ROWS = 10; const int MAX_COLS = 10; class MatrixType { public: MatrixType(); void MakeEmpty(); void SetSize(int rowsSize, int colSize); void StoreItem(int item, int row, int col); void Add(MatrixType otherOperand, MatrixType& result); void Sub(MatrixType otherOperand, MatrixType& result); void Mult(MatrixType otherOperand, MatrixType& result); void Print(ofstream& outfile); bool AddSubCompatible(MatrixType otherOperand); bool MultCompatible(MatrixType otherOperand);...

  • IN C++ Please!! Declare a global integer constant called SIZE and initialize it to 10. •...

    IN C++ Please!! Declare a global integer constant called SIZE and initialize it to 10. • Declare a global enum variable that will support 10 values – each representing an ant colony {A, B, C, D, E, F, G, H, I, J}. • In the main function, o Declare a 2-dimensional array of size the global integer constant, SIZE. The number of rows and columns should be equal to SIZE, which would make this a square matrix. This array will...

  • P7.5– A theater seating chart is implemented as a two-dimensional array of ticket prices, like this:...

    P7.5– A theater seating chart is implemented as a two-dimensional array of ticket prices, like this: 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 20 20 20 20 20 20 10 10 10 10 20 20 20 20 20 20 10 10 10 10 20 20 20 20 20 20 10 10 20 20 30 30...

  • /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid...

    /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid input examples: F00D, 000a, 1010, FFFF, Goodbye, BYE Enter BYE (case insensitive) to exit the program. ****************************************************/ import java.util.Scanner; public class HexUtilitySOLUTION { public static void main(String[] args) { // Maximum length of input string final byte INPUT_LENGTH = 4; String userInput = ""; // Initialize to null string Scanner input = new Scanner(System.in); // Process the inputs until BYE is entered do {...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT