Question: Write the following C++ code in MIPS assembly language Find all elements with X and replace with Y The array is an integer array You

Write the following C++ code in MIPS assembly language

Find all elements with X and replace with Y

The array is an integer array

You must have the main function and another function called replace:

int replace(int,int,int,int[]);

int main() {

int a[5]; //declare an array

a[0]=2; //array int

a[1]=3;

a[2]=4;

a[3]=4;

a[4]=5;

cout << a[] << endl; //show initial values

replace(4,10,5,a); //replace all instances of "4" in the

// array with "10"

//array length is 5, and passing array a

cout << a << endl; //show new values

}

int replace (int existing, int newitem, int size, int a[])

{

int i;

for (i=0; i < size; i++)

{

if (a[i]==existing)

a[i] = newitem;

}

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 Databases Questions!