Write the MIPS function calc to do the following You do not

Write the MIPS function \"calc\" to do the following. You do not need to write an entire program, just the function.

c = a + b + 2;

Parameters:

$a0: address of a

$a1: address of b

$a2: address of c

Solution

IF You\'re the Callee then the MIPS function will be assined like that MIPS designates 8 registers $s0-$s7 as saved registers. It\'s up to the callee to save the registers if they\'re being used. This is not handled automatically by the CPU. It\'s merely a convention that\'s followed by MIPS programmers. This seems like a great idea. Let\'s say you are writing subroutine FOO, and subroutine FOO calls subroutineBAR. So, you think \"I\'m going to use registers $s0-$s7 because they\'re saved by the callee, so when I call BAR, then BAR will save it for me\". And therefore, you don\'t think it\'s necessary to save the saved registers. Except that\'s not the correct view. Any subroutine can serve as the caller and the callee. In fact, your initial view as a subroutine writer is to imagine you\'re the callee. After all, you\'re providing a subroutine for others to use (which could be you). It\'s easy to think of yourself as the caller, but think first as a callee. Since you now view yourself as a callee, this is what you need to do: Step 1: Determine what saved registers you intend to use Step 2: Push those saved registers onto the stack Step 3: Use the saved registers and run the main part of the subroutine code. Step 4: Just before you return from the subroutine call, pop the saved registers Step 5: Return back to the subroutine that called you. Suppose you\'re in Step 3. You\'ve pushed the saved registers on the stack, and now you\'re running code. You decide to call a subroutine. Do you need to resave the saved registers? At this point, you can imagine yourself as the caller, and thus, you don\'t have to save the registers a second time. In fact, you already saved them in Step 2. The subroutine you\'re about to call will save any registers it needs on the stack, which may be different from the registers you saved. It doesn\'t really matter because it\'s up to that subroutine to figure it out. So, the right mindset to writing a subroutine is to think \"I\'m the callee\".

HERE THE MAIN DIFFERENCE FOR ALL THE ELEMENTS I AM SHOWING

Logical ops C operators Java operators MIPS instr

Shift Left << << sll

Shift Right >> >>>   srl

Bit-by-bit AND & & and,andi

Bit-by-bit OR | | or, ori

Bit-by-bit NOT ~ ~ nor

AND THE CODE WILL BE LIKE THIS IM EXPLAININING BELOW

This segment of a C program contains the five variables a, b, c and 2:

The translation from C to MIPS instructions is performed by the compiler. Show the MIPS code produced by the C compiler.

Answer: The C compiler could produce

These instructions are symbolic representations of what the processor understands; they are called assembly language instructions.

Another more complex example

Answer

Write the MIPS function \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site