Assembly Part 8 Flashcards
Two D array: T A[R][C]
What is the size of the array
RCK
To get access to a specified nested array
- Compute th address to the desired row
- Compute the offset within the row to the desired element
- Add 1 and 2; result is address of desired element
How to get the address of A[i]
Each element of type T requires K bytes
Starting address: A + i(CK)
How to get address of A[i][j]
Each element is of type T which requires K bytes
A + (i(CK)) + jK = A + ((iC) + j)*K
Suppose we have
Int *univ[3] = {mit, come, ucb}
MIT, cmu, and ucb are arrays
What is the computation
Must do TWO MEMORY READS
Mem[Mem[univ + 8index] + 4digit]
a in %rdi, i in %rsi, j in %rdx
Int a[16][16]
Total size of array:
16164 = 1024 bytes
Salq $6, %rsi
Addq %rsi, %rdi
Movl (%rdi, %rdx,4), %eax
n in %rdi, a in %rsi, i in %rdx, j in %rcx
Non matrix access
Imulq %rdx, %rdi. Rdi = ni
Leaq (%rsi, %rdi, 4), %rax. #a + 4n*i
Movl (%rax, %rcx, 4), %eax
Ret