Question: I need help with this MIPS program. Write a MIPS program that contains a function called add_one. The function should implement the following C code:

I need help with this MIPS program.

Write a MIPS program that contains a function called add_one. The function should implement the following C code:

int add_one(int number) { return number + 1; }

In the main part of your program, you should call your function, passing it the number 9. You should then print what it returns using syscall 1.

Note that since main is no longer a leaf function, you'll need to allocate a stack frame for it! Since add_one is a leaf function, it will not need a stack frame.

Part 2:

In this exercise, you will add to your program from the last exercise. Write an additional function called multiply_by_two. The function should implement the following C code:

int multiply_by_two(int number) { return number * 2; }

HINT: Think about how you might use a shift instruction to implement this.

Now, add a third function called times_two_plus_one. This function should implement the following C code:

int times_two_plus_one(int number) { return add_one(multiply_by_two(number)); } 

In the main part of your program, you should call your function, passing it the number -3. You should then print what it returns using syscall 1.

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!