From 8092f4c334db547ced59d6f439b558dad35e1ab2 Mon Sep 17 00:00:00 2001 From: Mike Vink Date: Fri, 14 Jun 2024 09:23:32 +0200 Subject: commit for once --- 3/9_data_structures/41_struct_test.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 3/9_data_structures/41_struct_test.c (limited to '3/9_data_structures/41_struct_test.c') diff --git a/3/9_data_structures/41_struct_test.c b/3/9_data_structures/41_struct_test.c new file mode 100644 index 0000000..1816b31 --- /dev/null +++ b/3/9_data_structures/41_struct_test.c @@ -0,0 +1,30 @@ +struct test { + short *p; + struct { + short x; + short y; + } s; + struct test *next; +} + +// A. +// p: 0, it's at the beginning of the struct +// s.x: (length p) <- 8 +// s.y: (length p) + (length s.x) <- 10 +// next: (length p) + (length s.x) + (length s.y) <- 12 +// B. +// total bytes should be 20. pointer + short + short + pointer +// C. +// st in %rdi +// st_init: +// movl 8(%rdi), %eax +// movl %eax, 10(%rdi) +// leaq 10(%rdi), %rax +// movq %rax, (%rdi) +// movq %rdi, 12(%rdi) +// ret +void st_init(struct test *st) { + st->s.y = st->s.x; + st->p = &(st->s.y); + st->next = st; +} -- cgit v1.2.3