Question: int mat 1 [ M ] [ N ] ; int mat 2 [ N ] [ M ] ; int sum _ element (

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 assembly code:
; on entry , i is in % edi , j is in % esi
; movslq converts long to quad
; leaq offset ( R1, R2, I ) computes address I * R2+ R1+ offset
; sal is a shift left
sum_element :
movslq % esi ,% rsi
movslq % edi ,% rdi
leaq (% rdi ,% rdi ,4),% rax
leaq (% rdi ,% rax ,2),% rdx
addq % rsi ,% rdx
leaq (% rdi ,% rdi ,2),% rcx
movq % rcx ,% rax
salq $4,% rax
subq % rdi ,% rax
addq % rsi ,% rax
movl mat2(,% rax ,4),% eax
addl mat1(,% rdx ,4),% eax
ret
(1) What is the value of M?
(2) What is the value of N?
(3) Due to a bug, the program tried to reference mat1[3][-9]. Which element of mat1 will
actually be accessed?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!