1. Engineering
  2. Computer Science
  3. 1 the traditional way in which we swap two values...

Question: 1 the traditional way in which we swap two values...

Question details

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.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution