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
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