[prev] 15 [next]

2-d Arrays in MIPS (cont)

Representations of  int matrix[4][4] ...

# for strategy (a)
#This is the strategy we will be mostly using in this course
matrix: .space 64
# for strategy (b)
row0:   .space 16
row1:   .space 16
row2:   .space 16
row3:   .space 16
matrix: .word row0, row1, row2, row3

Now consider summing all elements

int i, j, sum = 0;
for (i = 0; i < 4; i++)
   for (j = 0; j < 4; j++)
      sum += matrix[i][j];