summaryrefslogtreecommitdiff
path: root/3/9_data_structures/43_dest.c
diff options
context:
space:
mode:
Diffstat (limited to '3/9_data_structures/43_dest.c')
-rw-r--r--3/9_data_structures/43_dest.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/3/9_data_structures/43_dest.c b/3/9_data_structures/43_dest.c
new file mode 100644
index 0000000..67bb630
--- /dev/null
+++ b/3/9_data_structures/43_dest.c
@@ -0,0 +1,43 @@
+#define type long;
+
+typedef union {
+ struct {
+ long u;
+ short v;
+ char w;
+ } t1;
+ struct {
+ int a[2];
+ char *p;
+ } t2;
+} u_type;
+
+// Kinda confused when I'm moving a memory address
+// Forgot it was a union
+// Also forgot I had to move to dest
+//
+// up and dest in rdi and rsi
+//
+// expr type code
+//
+// up->t1.u long movq (%rdi), %rax
+// movq %rax, (%rsi)
+//
+// up->t1.v short movw 8(%rdi), %ax
+// movw %ax, (%rsi)
+//
+// &up->t1.w char* addq 10, %rdi
+// movq %rdi, (%rsi)
+//
+// up->t2.a int * movq %rdi, (%rsi)
+//
+// up->t2.a[up->t1.u] int movq (%rdi), %rax // What's interesting: rdi is the t2.a int* and the t1.u long, and they are being used in the same expression!
+// movl (%rdi, %rax, 4), %eax
+// movl %eax, (%rsi)
+//
+// *up->t2.p char movq 8(%rdi), %rax
+// movb (%rax), %al // Remember, you cannot have Memory -- Memory moves!
+// movb %al, (%rsi)
+void get(u_type *up, type *dest) {
+ *dest = ___;
+}