Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Instructor note: Hint: Use add, jal instructions in the main assembly. Do not use lw , sw instructions. Notice that when

Instructor note:
Hint:
Use "add", "jal" instructions in the main assembly. Do not use "lw","sw" instructions.
Notice that when the Sum() and Dif() functions are called, the arguments are flipped: (x, y) and (y, x)
Given the following C program and the mapping of registers to variables, complete the MIPS implementation of Main. Do not implement return 0; in main().
int Dif(int a, int b){
return a - b;
}
int Sum(int a, int b){
return a + b;
}
int main(){
int x, y;
w = Sum(x, y);
z = Dif(y, x);
return 0; // Do not implement
}
Registers Variables
$s0 x
$s1 y
$s2 w
$s3 z
Hint: Use a0, a1 as arguments and v0 as return value, according to the register conventions.
Ex: If the values of $s0 and $s1 are initialized in the simulator as:
Registers Data
$s05
$s110
the results are stored in $s2 and $s3:
Registers Data
$s05
$s110
$s215
$s35
Note: Use the '+' button under the Registers display to initialize register values for $s0 and $s1.
Assembly Code:
Main:
# Type your code here.
j End
# Procedure Sum (Do not modify)
Sum:
add $v0, $a0, $a1
jr $ra
# Procedure Dif (Do not modify)
Dif:
sub $v0, $a0, $a1
jr $ra
End:
-----
Registers:
$s0: 0
$s1: 0
-------
Please provide the correct answer by using the assembly code I provided and any adjustments to the registers provided as well ( as shown in the screenshot)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions