I have this code snippet:

  for (i=0; i<=100; i++) {
           a[i] = b[i] + C ;
     }

I am trying to figure out what this would look like in MIPS assembly with these rules:

Assume that a and b are arrays of words and the base address of a is in $a0 and the base address of b is in $a1. Register $t0 holds the variable i and register $s0 the constant C. Write the code for MIPS. How many instructions are executed during the running of your code? How many memory data references will be made during execution?

I don't even know how to start on this.. Can someone help me figure this out? Im so stuck. Thanks

This looks an awful lot like an exam question, which makes me wonder if I should bother, but here goes.

Regarding the loop itself, do you know how to a) set a register's value to zero, b) compare two values for equality, and c) add one to a register and store the result in the same register? This is assuming a naive implementation; there are ways to do this that would be more efficient, but I figure I'll keep this simple.

Inside the loop, you have the bases of the two arrays given to you in the $a0 and $a1 registers. You will need to increment the registers on each pass of the loop, to walk through the arrays. You will also have to add the value in the second array at a given index to $s0, and store it in the offset value of $a0. This should be trivial, if you have done what has already been mentioned.

Oh BTW, does the instructor allow you to use psuedo-instructions such as la and move? That will make things much easier if you can.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.