So I'm trying to compute the values of M and N in the following code with the assembly code given.
int array1[M][N];
int array2[N][M];
void copyelement(int i, int j) {
array1[i][j] = array2[j][i];
}
Assembly:
copyelement:
movslq %esi, %rsi
movslq %edi, %rdi
leaq (%rdi,%rdi,8), %rax
addq %rsi, %rax
leaq (%rsi,%rsi,2), %rdx
leaq (%rsi,%rdx,4), %rdx
addq %rdx, %rdi
leaq array2(%rip), %rdx
movl (%rdx,%rdi,4), %ecx
leaq array1(%rip), %rdx
movl %ecx, (%rdx,%rax,4)
ret
While reading through the assembly code, I got through till array2(%rip)
and then I didn't know how to move forward.
At this point, according to my calculations I should have
%rdx = %rdi + (%rsi + %rax) + 4*((%rsi+%rax) + 2*(%rsi + %rax))
.
Also I'm not quite sure how I would be able to get the array size from this.