Question
I: Write a MIPS program that asks the user for two number inputs (first procedure), then have it ask for a type of operations (add,
I: Write a MIPS program that asks the user for two number inputs (first procedure), then have it ask for a type of operations (add, or multiply), the second procedure should call a third procedure which actually performs the operation as requested.
Feel free to create any extra methods or variables you think you might need, you should probably store A and B in either the $s registers or $a registers (or both, depending on how you do this). Try and catch any overflow exceptions.
Hint: Do the Sri part last as its recursive and a bit tricky.
Pseudocode example:
main()
{
GetInputs();
Print(GetOps(A,B));
}
void GetInputs{
int A=ReadNumber();
int B=ReadNumber();
}
int GetOps
{
Op=ReadString();
if (Op = "add")
result = Add(A,B);
else if (Op = Sri)
result = Sri(A,B);
else
result = Multiply(A,B);
return result;
}
int Add(A, B)
{
return A + B;
}
int multiply(A, B)
{
return A*B;
}
int Sri (A,B)
{
if (A <=1) or (B<=1)
return 1;
else return A*B*Sri(A-1, B-1);
}
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