3.64

A.

3.1 in book

T D[R][C];

&D[i][j] = Xd + L(C*i + j)

T means type, D means data, R means row, C means column

L means sizeof(T), Xd means address of D

similarly, in 3d array

TYPE D[R][S][T]

&D[i][j][k] = Xd + L(S*T*i + T*j + k)

B.

.section .data
.global A
A:
  .fill 3640/8, 8, 121 # fill data 121

.section .text
.global store_ele
# long store_ele(long i, long j, long k, long *dest)
# i in %rdi, j in %rsi, k in %rdx, dest in %rcx
store_ele:
  leaq (%rsi, %rsi, 2), %rax    # t1 = j*3
  leaq (%rsi, %rax, 4), %rax    # t1 = j*13
  movq %rdi, %rsi               # t2 = i
  salq $6, %rsi                 # t2 = i*64
  addq %rsi, %rdi               # t3 = i*65
  addq %rax, %rdi               # t3 = i*65 + j*13
  addq %rdi, %rdx               # t4 = i*65 + j*13 + k
  movq A(,%rdx,8), %rax         # t1 = *(A + 8*t4)
  movq %rax, (%rcx)             # *dest = t1
  movl $3640, %eax              # return 3640
  ret

base on comments,

S * T = 65
T = 13
8*R*S*T = 3640

so

R = 7
S = 5
T = 13
comments powered by Disqus