Question
1- The traditional way in which we swap two values is to use a temporary variable as follows: int temp = a; a = b;
1- The traditional way in which we swap two values is to use a temporary variable as follows:
int temp = a;
a = b;
b = temp;
(a) Translate this code to MIPS, assuming a is in $s0 and b is in $s1.
(b) We can actually swap two values without using a temporary variable. Determine this method (it involves the same number of statements, but uses some arithmetic/logical expressions) and translate this into MIPS.
(c) What is an advantage of this latter method?
2- Translate the following code into MIPS assembly language
sum = 0;
for(i=1; i<=j; i++)
sum += i;
Assume sum, i, and j are in registers $s0, $s1 and $s2, respectively. Determine the total number of instructions executed, in terms of the value of j.
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