diff options
| author | Mike Vink <mike@pionative.com> | 2024-06-14 09:23:32 +0200 |
|---|---|---|
| committer | Mike Vink <mike@pionative.com> | 2024-06-14 09:23:32 +0200 |
| commit | 8092f4c334db547ced59d6f439b558dad35e1ab2 (patch) | |
| tree | fa462fa885efea1ec6095d015286998d632c2c3d /3/9_data_structures/41_struct_test.c | |
| parent | b424517a33bf61aedff29eed74a665402ab496ba (diff) | |
commit for once
Diffstat (limited to '3/9_data_structures/41_struct_test.c')
| -rw-r--r-- | 3/9_data_structures/41_struct_test.c | 30 |
1 files changed, 30 insertions, 0 deletions
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; +} |
