Adding comments will always help. The "trick" is that computing the addresses of the array elements must involve multiplying by the 2d array row length. You just need to figure out those multipliers:
# On entry:
# %edi = x
# %esi = y
copy_array:
movslq %edi,%rdi ; %rdi = x
movslq %esi,%rsi ; %rsi = y
movq %rsi, %rdx ; %rdx = y
salq $4, %rdx ; %rdx *= 16
subq %rsi, %rdx ; %rdx -= y (so now %rdx = 15 * y)
addq %rdi, %rdx ; %rdx += x (so now %rdx = 15 * y + x)
leaq 0(,%rdi,8), %rax ; %rax = 8 * x
subq %rdi, %rax ; %rax -= x (so now %rax = 7 * x)
addq %rsi, %rax ; %rax += y (so now %rax = 7 * x + y)
movl array1(,%rax,4), %eax ; %rax = array1[7 * x + y]
movl %eax, array2(,%rdx,4) ; array2[15 * y + x] = %rax
ret
Now since C arrays are stored in row major order, the rows of array1
must be 7 elements long (i.e. the array has 7 columns) and those of array2
are 15 (i.e. it has 15 columns). This means J = 7 and H = 15 as you said in your question.