diff options
| author | Mike Vink <mike@pionative.com> | 2024-05-28 08:49:46 +0200 |
|---|---|---|
| committer | Mike Vink <mike@pionative.com> | 2024-05-28 08:49:46 +0200 |
| commit | b424517a33bf61aedff29eed74a665402ab496ba (patch) | |
| tree | 1897e147cf15f5c7a121a73fc003b32639a697ea /3/7_procedures | |
| parent | 758543aef80c3b3568a20b0dff20202c796a4819 (diff) | |
procedures
Diffstat (limited to '3/7_procedures')
| -rw-r--r-- | 3/7_procedures/32_functions.c | 14 | ||||
| -rw-r--r-- | 3/7_procedures/33_procprob.c | 21 | ||||
| -rw-r--r-- | 3/7_procedures/34_long_p.c | 34 |
3 files changed, 69 insertions, 0 deletions
diff --git a/3/7_procedures/32_functions.c b/3/7_procedures/32_functions.c new file mode 100644 index 0000000..ebf4405 --- /dev/null +++ b/3/7_procedures/32_functions.c @@ -0,0 +1,14 @@ +// Label PC Instruction %rdi %rsi %rax %rsp *%rsp Description +// M1 400560 callq 10 7fffffffe820 Call first(10) +// +// F1 400548 lea 10 7fffffffe818 400565 v <- x + 1 +// F2 40054c sub 10 11 7fffffffe818 400565 u <- x - 1 +// F3 400550 callq 9 11 7fffffffe818 400565 Call last(9, 11) +// +// L1 400540 mov 9 11 7fffffffe810 400555 rax <- u +// L2 400543 imul 9 11 9 7fffffffe810 400555 rax <- rax * v +// L3 400547 retq 9 11 99 7fffffffe810 400555 return +// +// F4 400555 retq 9 11 99 7fffffffe818 400565 return +// +// M2 400565 mov 9 11 99 Resume diff --git a/3/7_procedures/33_procprob.c b/3/7_procedures/33_procprob.c new file mode 100644 index 0000000..4c68855 --- /dev/null +++ b/3/7_procedures/33_procprob.c @@ -0,0 +1,21 @@ +// procprob +// movslq %edi, %rdi movslq==Move and sign extend 32bit to 64bit two's complement number, +// Basically seems to convert the first signed argument to 64bit size. +// A singed 32bit number is an int? +// addq %rdi, (%rdx) *u <- (long) u + (long) a +// addb %sil, (%rcx) *v <- (char) *v + (?) b +// movl $6, %eax sizeof(a) + sizeof(b) = 6 = 4 + 2 +// +// procprob +// movslq %edi, %rdi movslq==Move and sign extend 32bit to 64bit two's complement number, +// Basically seems to convert the first signed argument to 64bit size. +// A singed 32bit number is an int? +// addq %rdi, (%rdx) *u <- (long) u + (long) a +// addb %sil, (%rcx) *v <- (char) *v + (?) b +// movl $6, %eax sizeof(a) + sizeof(b) = 6 = 2 + 4 +// +int procprob(int a, short b, long *u, char *v) { + *u += a; + *v += b; + return sizeof(b) + sizeof(b) +} diff --git a/3/7_procedures/34_long_p.c b/3/7_procedures/34_long_p.c new file mode 100644 index 0000000..d058b77 --- /dev/null +++ b/3/7_procedures/34_long_p.c @@ -0,0 +1,34 @@ +// long P(long x) +// x in %rdi +// bx and bp, r12-15 are callee saved +// +// P: +// pushq %r15 +// pushq %r14 +// pushq %r13 +// pushq %r12 +// pushq %rbp +// pushq %rbx +// subq $24, %rsp Allocate 24 extra bytes +// +// movq %rdi, %rbx move first arg into rbx +// leaq 1(%rdi), %r15 move first arg into rbx +// leaq 2(%rdi), %r14 move first arg into rbx +// leaq 3(%rdi), %r13 move first arg into rbx +// leaq 4(%rdi), %r12 move first arg into rbx +// leaq 5(%rdi), %rbp move first arg into rbx +// leaq 6(%rdi), %rax move first arg into rbx +// movq %rax, (%rsp) save %rax in one of the three 8byte spots +// leaq 7(%rdi), %rdx move first arg into rdx +// movq %rdx, 8(%rsp) save %rdx in the second of the three 8byte spots +// movl $0, %eax set ax to zero? +// call Q +// ... +// +// A. x, x + 1, x + 2, x + 3, x + 4, x + 5 +// B. x + 6, x + 7 +// C. There were more than 6? +// +long P(long x) { + return 0; +} |
