I have to use the assembly code to find the value of P. How do I read this? I am not quite sure how to begin. If anyone could help me by either going through it step by step or just explaining it to me. Either way would be a big help
in C:
#define P ?
#define Q ?
int mat1[P][Q];
int mat2[Q][P];
void copy_element( int i, int j) {
mat1[ i ][ j ] = mat2[ j ][ i ];
in assembly:
copy_element:
movslq %edi, %rdi
movslq %esi, %rsi
movq %rsi, %rax
salq $4, %rax
subq %rsi, %rax
addq %rdi, %rax
movl mat2(,%rax,4), %ecx
leaq (%rdi, %rdi, 4), %rdx
leaq 0(, %rdx, 4), %rax
addq %rax, %rsi
movl %ecx, mat1,(,%rsi,4)
ret
My full try:
copy_element:
movslq %edi, %rdi ?(rdi = i)
movslq %esi, %rsi (rsi = j)
movq %rsi, %rax (rax = j)
salq $4, %rax (rax = 16j)
subq %rsi, %rax (rax = 15j)
addq %rdi, %rax (rax = 15j + i)?
movl mat2(,%rax,4), %ecx (ecx = 60j + 4i)?
leaq (%rdi, %rdi, 4), %rdx (rdx = 5i)
leaq 0(, %rdx, 4), %rax (rax = 20i)? or maybe (rax = 15j + 21i)?
addq %rax, %rsi (rsi = j + 20i)
movl %ecx, mat1,(,%rsi,4) what?? (? = 64j + 80i)
ret
P = 60 and Q = 80?
or are they P = 15 and Q = 20?
of course both could be wrong
(I am sorry if this question is bothersome or if I didn't do something correctly.)