M and N are constants defined by #define
int mat1[M][N];
int mat2[N][M];
int sum_element(int i, int j) {
return mat1[i][j] + mat2[i][j];
}
Suppose the above code generates the following in assembly:
sum_element:
pushl %ebp
movl %esp,%ebp
movl 8(%ebp),%eax
movl 12(%ebp),%ecx
sall $2,%ecx
leal 0(,%eax,8),%edx
subl %eax,%edx
leal (%eax,%eax,4),%eax
movl mat2(%ecx,%eax,4),%eax
addl mat1(%ecx,%edx,4),%eax
movl %ebp,%esp
popl %ebp
ret