summaryrefslogtreecommitdiff
path: root/3/8_array_allocation_and_access/38_nested_arrays.c
diff options
context:
space:
mode:
Diffstat (limited to '3/8_array_allocation_and_access/38_nested_arrays.c')
-rw-r--r--3/8_array_allocation_and_access/38_nested_arrays.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/3/8_array_allocation_and_access/38_nested_arrays.c b/3/8_array_allocation_and_access/38_nested_arrays.c
new file mode 100644
index 0000000..b53c7be
--- /dev/null
+++ b/3/8_array_allocation_and_access/38_nested_arrays.c
@@ -0,0 +1,18 @@
+#define M 20;
+#define N 30;
+
+long P[5][7];
+long Q[7][5];
+
+// i in rdi, j in rsi
+// sum_element:
+// leaq 0(,%rdi, 8), %rdx %rdx <- 8*i
+// subq %rdi, %rdx %rdx <- %rdx - i
+// addq %rsi, %rdx %rdx <- %rdx + j
+// leaq (%rsi, %rsi, 4), %rax %rax <- 5j
+// addq %rax, %rdi %rdi <- %rax + %rdi // rdi <- 5j + i
+// movq Q(, %rdi, 8), %rax %rax <- xq + 8(5j + i)
+// addq P(, %rdx, 8), %rax %rax <- %rax + xp + 8(7i + j)
+long sum_element(long i, long j) {
+ return P[i][j] + Q[j][i];
+}