Side-by-side comparison of C and mips assembly

A function to reverse an array of int into another array: (Class example, February 2013)

#include <stdio.h>
/* Reverse an array, into another array */
int source[SIZE] = {2,4,6,8,10,42}; //test data
#define SIZE 6
int dest[SIZE]; //42,10,8,6,4,2 expected



void reverse (int * d, const int s[], int n)
{ d = d + n; //point past end of destination

while (n--) // more numbers to move

*(--d) = *s++; // copy and move pointers
}




int main() {
int i;
reverse (dest, source, SIZE);
for (i=0; i<SIZE; i++)
printf("%4d %4d\n",source[i],dest[i]);
return 0;
}

# MIPS function to reverse an array s to destination dest
.data
source: .word 2,4,6,8,10,42
size: .word 6
dest: .space 6*4
endl: .asciiz "\n"
.text
.globl __start
reverse: # a0 -> dest, a1 -> source, a2 = size
sll $t0,$a2,2 # bytes in dest (size*4)
add $a0,$a0,$t0 # past end of dest
rwhile: beqz $a2, rend # no more numbers
sub $a2, $a2, 1 # n--
lw $t0,($a1) # load word from source *s
add $a1, $a1, 4 # post-increment s s++
sub $a0, $a0, 4 # pre-decrement d d--
sw $t0,($a0) # store in dest *d
j rwhile
rend: jr $ra # return
__start:
la $a0, dest # address of dest
la $a1, source # address of source
lw $a2, size # size of arrays
jal reverse # reverse(dest, source, size)
# --- now code to print dest ----

Notice that int * d  and int d[] mean exactly the same thing: the argument d must be a pointer to a memory word to hold an int. Presumably there are other ints to follow, up to n of them
Since a while loop goes through the loop unless the condition is false (zero), notice that the test will always be implemented by beqz to the line immediately following the j rwhile that forms the end of the loop.
The * operator translates to either lw or sw, depending on where it appears. It will be lw unless it is on the LEFT of =, an "lvalue".