For an academic problem, given the following big-endian MIPS code (highest memory address at left, lowest at right), I have been asked to provide the MIPS code from hex and its equivalent C code, as well as some context to the C code.
80 48 05 00 20 48 89 00 00 00 28 8d 04 00 2a ad 00 00 2a ad 04 00 28 ad 08 00 e0 03
I have disassembled the MIPS code and converted it into some C code. I wanted to know if I mess up the byte ordering during the disassembling process since the C code doesn't seem to have a purpose rather than variable assignments, or if I mess up the C code so that it appears to be irrelevant.
Please note that the initializations of the variables and array size are just placeholders (they are not part of the MIPS code at all), so that the program can run with error.
Any help is much appreciated!
MIPS:
Big Endian Little Endian Binary Representation (Little Endian) MIPs Code
80480500 00054880 000000 00000 00101 01001 00010 000000 sll $t1, $a1, 2
20488900 00894820 000000 00100 01001 01001 00000 100000 add $t1, $a0, $t1
0000288d 8d280000 100011 01001 01000 0000000000000000 lw $t0, 0x0000($t1)
04002aad ad2a0004 101011 01001 01010 0000000000000100 sw $t2, 0x0004($t1)
0000a2ad ad2a0000 101011 01001 01010 0000000000000000 sw $t2, 0x0000($t1)
040028ad ad280004 101011 01001 01000 0000000000000100 sw $t0, 0x0004($t1)
0800e003 03e00008 000000 11111 00000 00000 00000 001000 jr $ra
C:
#include <stdio.h>
int main(void) {
int i = 0, t0 = 1, t2 = 2;
int A[10];
t0 = A[i];
A[i + 1] = t2;
A[i] = t2;
A[i] = t0;
return 0;
}