I have a segment of C++ code that I need to convert to mips using direct translation. I have most of it done, its a do while loop. I just don't understand this one line in MIPS.
x[i] = y[i];
I don't understand how to convert this into mips and I've been searching endlessly online. Could I get any help?
EDIT
This is what I had but was told it was incorrect:
la $6, y
Li $7, $1
Add $7, $7, $7
Add $7, $7, $7
Add $8, $6, $7
Lw $6, 0($8)
La $7, x
Li $8, $1
Add $8, $8, $8
Add $8, $8, $8
Add $7, $7, $8
Sw $6, 0($7)
I used this online site as reference:
http://www.cs.pitt.edu/~xujie/cs447/AccessingArray.htm
SECOND EDIT
C++ Coding
i=0;
do {
x[i]=y[i];
i++;
}
while (i!=j);
MIPS Direct translation
Addi $1, $1, 0
Loop: la $6, y
Li $7, $1
Add $7, $7, $7
Add $7, $7, $7
Add $8, $6, $7
Lw $6, 0($8)
La $7, x
Li $8, $1
Add $8, $8, $8
Add $8, $8, $8
Add $7, $7, $8
Sw $6, 0($7)
Addi $1, $1, 1
Bne $1, $2, loop
And here are all my registers I can use to avoid confusion to you:
Variables i j x y 4 (constant) Free
Registers $1 $2 $3 $4 $5 $6, $7, $8
This should get you into the right direction. Since this is a homework question, I'm not going to give you a complete solution.
Quick Reference (MIPS instructions, calling convention, etc):
http://www.mips.com/media/files/MD00565-2B-MIPS32-QRC-01.01.pdf
An example assembly function that computes the dot product of a 32-bit and a 16-bit vector in a little-Endian environment:
http://code.google.com/p/mips32-asm/source/browse/dot32x16.S
Here you can see how the elements of arrays are accessed.
Note that ".set reorder" makes the assembler reorder the instructions and/or include NOPs to deal with the so-called delay slot. In case your professor wants to see that you understood the delay slot issue, you should order the instructions yourself properly and/or write your own NOP after a branch/jump.