Question
Topic is MIPS Assembly Language. The following main program and 4 parameter function are written in the high level language C: int f(int a, int
Topic is MIPS Assembly Language.
The following main program and 4 parameter function are written in the high level language C:
int f(int a, int b, int c, int d) { /* start the programming for function f*/ int x; x = a + b + c + d; if (x == 2) { /* start the if part of the if... else logic for this function */ return (x); } else { /* start the else part of the if... else logic for this function */ if (a < b) { return (a); } /* end if (a < b) */ if (a == b) { return (b); } /* end if (a == b) */ if (a > b) { return (x); } /* end if (a > b) */ } /* end if.. else*/ } /* end function f*/ int main() { int result = 0; result = f(12,7,20,21); return (result); } // end main
The main function is used in C to hold the programming logic that is performed when the program runs. The main function can call other functions as a part of its programming logic. In this program, the main function is calling the f function.
Translate this C program into a MIPS assembly program. In your translation, you are to use the following rules:
All parameter passed to a function must have their values placed in the parameter registers $a0, $a1, $a2, and $a3 before the function is called.
- All integer values are 32 bits long.
- All values returned from a function must be stored in the $v0 register.
Program expectations:
- the assembly language translation you write follows the rules above, and has all the equivalent programming logic as the C program. All of the programming logic for both the C program's main function and the C program's function f must be in your translation
- the assembly language translation you write executes without any errors
- the assembly language translation you write provides the same value for $v0 in the last instruction of the program as the value of result in the C program's main function
- the assembly language translation contains program comments that state your name, the programming logic, and any details you feel you'd like to explain that state about how you are using the assembly language instructions
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