Mercurial > pub > dyncall > dyncall
comparison doc/disas_examples/x64.sysv.disas @ 327:c0390dc85a07
- doc: added disassembly examples for many platforms and calling conventions, for reference
author | Tassilo Philipp |
---|---|
date | Fri, 22 Nov 2019 23:08:59 +0100 |
parents | |
children | fb51dc714566 |
comparison
equal
deleted
inserted
replaced
326:09aaa2e774cd | 327:c0390dc85a07 |
---|---|
1 ; #include <stdlib.h> | |
2 ; | |
3 ; void leaf_call(int b, int c, int d, int e, int f, int g, int h) | |
4 ; { | |
5 ; } | |
6 ; | |
7 ; void nonleaf_call(int a, int b, int c, int d, int e, int f, int g, int h) | |
8 ; { | |
9 ; /* use some local data */ | |
10 ; *(char*)alloca(10) = 'L'; | |
11 ; leaf_call(b, c, d, e, f, g, h); | |
12 ; } | |
13 ; | |
14 ; int main() | |
15 ; { | |
16 ; nonleaf_call(0, 1, 2, 3, 4, 5, 6, 7); | |
17 ; return 0; | |
18 ; } | |
19 | |
20 | |
21 | |
22 ; output from freebsd-12.0-x64 w/ clang 6.0.1 | |
23 | |
24 0000000000000000 <leaf_call>: | |
25 0: 55 push %rbp | |
26 1: 48 89 e5 mov %rsp,%rbp | |
27 4: 8b 45 10 mov 0x10(%rbp),%eax | |
28 7: 89 7d fc mov %edi,-0x4(%rbp) | |
29 a: 89 75 f8 mov %esi,-0x8(%rbp) | |
30 d: 89 55 f4 mov %edx,-0xc(%rbp) | |
31 10: 89 4d f0 mov %ecx,-0x10(%rbp) | |
32 13: 44 89 45 ec mov %r8d,-0x14(%rbp) | |
33 17: 44 89 4d e8 mov %r9d,-0x18(%rbp) | |
34 1b: 89 45 e4 mov %eax,-0x1c(%rbp) | |
35 1e: 5d pop %rbp | |
36 1f: c3 retq | |
37 | |
38 0000000000000020 <nonleaf_call>: | |
39 20: 55 push %rbp ; | | |
40 21: 48 89 e5 mov %rsp,%rbp ; | prolog | |
41 24: 48 83 ec 40 sub $0x40,%rsp ; | open frame *with* static alloca() size included | |
42 28: 8b 45 18 mov 0x18(%rbp),%eax ; unsure... get stack param from prev frame into some scratch reg... but why? see below @@@ | |
43 2b: 44 8b 55 10 mov 0x10(%rbp),%r10d ; unsure... get stack param from prev frame into some scratch reg... but why? see below @@@ | |
44 2f: 89 7d fc mov %edi,-0x4(%rbp) ; in arg 0 -> local area (as temp store) | |
45 32: 89 75 f8 mov %esi,-0x8(%rbp) ; in arg 1 -> local area (as temp store) | |
46 35: 89 55 f4 mov %edx,-0xc(%rbp) ; in arg 2 -> local area (as temp store) | |
47 38: 89 4d f0 mov %ecx,-0x10(%rbp) ; in arg 3 -> local area (as temp store) | |
48 3b: 44 89 45 ec mov %r8d,-0x14(%rbp) ; in arg 4 -> local area (as temp store) | |
49 3f: 44 89 4d e8 mov %r9d,-0x18(%rbp) ; in arg 5 -> local area (as temp store) | |
50 43: c6 45 d0 4c movb $0x4c,-0x30(%rbp) ; 'L' -> local area (of alloca()'d space) | |
51 47: 8b 7d f8 mov -0x8(%rbp),%edi ; arg 0 | |
52 4a: 8b 75 f4 mov -0xc(%rbp),%esi ; arg 1 | |
53 4d: 8b 55 f0 mov -0x10(%rbp),%edx ; arg 2 | |
54 50: 8b 4d ec mov -0x14(%rbp),%ecx ; arg 3 | |
55 53: 44 8b 45 e8 mov -0x18(%rbp),%r8d ; arg 4 | |
56 57: 44 8b 4d 10 mov 0x10(%rbp),%r9d ; arg 5 (fetched from prev frame's param area - behind return addr on 16b aligned stack) | |
57 5b: 44 8b 5d 18 mov 0x18(%rbp),%r11d ; arg 6 (fetched from prev frame's param area), and ... | |
58 5f: 44 89 1c 24 mov %r11d,(%rsp) ; ... "pushed" onto stack | |
59 63: 44 89 55 cc mov %r10d,-0x34(%rbp) ; unsure... write something to local area @@@? | |
60 67: 89 45 c8 mov %eax,-0x38(%rbp) ; unsure... write something to local area @@@? | |
61 6a: e8 91 ff ff ff callq 0 <leaf_call> ; push return addr and call | |
62 6f: 48 83 c4 40 add $0x40,%rsp ; | | |
63 73: 5d pop %rbp ; | epilog | |
64 74: c3 retq ; | | |
65 75: 66 66 2e 0f 1f 84 00 nopw %cs:0x0(%rax,%rax,1) ; garbage data | |
66 7c: 00 00 00 00 ; garbage data | |
67 | |
68 0000000000000080 <main>: | |
69 80: 55 push %rbp ; | | |
70 81: 48 89 e5 mov %rsp,%rbp ; | prolog | |
71 84: 48 83 ec 20 sub $0x20,%rsp ; | | |
72 88: 31 ff xor %edi,%edi ; arg 0 | |
73 8a: be 01 00 00 00 mov $0x1,%esi ; arg 1 | |
74 8f: ba 02 00 00 00 mov $0x2,%edx ; arg 2 | |
75 94: b9 03 00 00 00 mov $0x3,%ecx ; arg 3 | |
76 99: 41 b8 04 00 00 00 mov $0x4,%r8d ; arg 4 | |
77 9f: 41 b9 05 00 00 00 mov $0x5,%r9d ; arg 5 | |
78 a5: b8 06 00 00 00 mov $0x6,%eax ; unsure... see below @@@? | |
79 aa: 41 ba 07 00 00 00 mov $0x7,%r10d ; unsure... see below @@@? | |
80 b0: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp) ; unsure... write 0 to local area @@@? | |
81 b7: c7 04 24 06 00 00 00 movl $0x6,(%rsp) ; "push" arg6 onto stack | |
82 be: c7 44 24 08 07 00 00 00 movl $0x7,0x8(%rsp) ; "push" arg7 onto stack | |
83 c6: 44 89 55 f8 mov %r10d,-0x8(%rbp) ; unsure... write something to local area @@@? | |
84 ca: 89 45 f4 mov %eax,-0xc(%rbp) ; unsure... write something to local area @@@? | |
85 cd: e8 4e ff ff ff callq 20 <nonleaf_call> ; push return addr and call | |
86 d2: 31 c0 xor %eax,%eax ; return value | |
87 d4: 48 83 c4 20 add $0x20,%rsp ; | | |
88 d8: 5d pop %rbp ; | epilog | |
89 d9: c3 retq ; | | |
90 | |
91 | |
92 | |
93 ; output from arch_linux-2011.08.19-x64 w/ gcc 4.6.1 (w/ alloca(220) instead of 10) | |
94 | |
95 0000000000000000 <leaf_call>: | |
96 0: 55 push %rbp | |
97 1: 48 89 e5 mov %rsp,%rbp | |
98 4: 89 7d fc mov %edi,-0x4(%rbp) | |
99 7: 89 75 f8 mov %esi,-0x8(%rbp) | |
100 a: 89 55 f4 mov %edx,-0xc(%rbp) | |
101 d: 89 4d f0 mov %ecx,-0x10(%rbp) | |
102 10: 44 89 45 ec mov %r8d,-0x14(%rbp) | |
103 14: 44 89 4d e8 mov %r9d,-0x18(%rbp) | |
104 18: 5d pop %rbp | |
105 19: c3 retq | |
106 | |
107 000000000000001a <nonleaf_call>: | |
108 1a: 55 push %rbp | |
109 1b: 48 89 e5 mov %rsp,%rbp | |
110 1e: 48 83 ec 30 sub $0x30,%rsp | |
111 22: 89 7d fc mov %edi,-0x4(%rbp) | |
112 25: 89 75 f8 mov %esi,-0x8(%rbp) | |
113 28: 89 55 f4 mov %edx,-0xc(%rbp) | |
114 2b: 89 4d f0 mov %ecx,-0x10(%rbp) | |
115 2e: 44 89 45 ec mov %r8d,-0x14(%rbp) | |
116 32: 44 89 4d e8 mov %r9d,-0x18(%rbp) | |
117 36: b8 10 00 00 00 mov $0x10,%eax | |
118 3b: 48 83 e8 01 sub $0x1,%rax | |
119 3f: 48 05 eb 00 00 00 add $0xeb,%rax | |
120 45: 48 c7 45 e0 10 00 00 00 movq $0x10,-0x20(%rbp) | |
121 4d: ba 00 00 00 00 mov $0x0,%edx | |
122 52: 48 f7 75 e0 divq -0x20(%rbp) | |
123 56: 48 6b c0 10 imul $0x10,%rax,%rax | |
124 5a: 48 29 c4 sub %rax,%rsp | |
125 5d: 48 8d 44 24 08 lea 0x8(%rsp),%rax | |
126 62: 48 83 c0 0f add $0xf,%rax | |
127 66: 48 c1 e8 04 shr $0x4,%rax | |
128 6a: 48 c1 e0 04 shl $0x4,%rax | |
129 6e: c6 00 4c movb $0x4c,(%rax) | |
130 71: 44 8b 45 e8 mov -0x18(%rbp),%r8d | |
131 75: 8b 4d ec mov -0x14(%rbp),%ecx | |
132 78: 8b 55 f0 mov -0x10(%rbp),%edx | |
133 7b: 8b 75 f4 mov -0xc(%rbp),%esi | |
134 7e: 8b 45 f8 mov -0x8(%rbp),%eax | |
135 81: 8b 7d 18 mov 0x18(%rbp),%edi | |
136 84: 89 3c 24 mov %edi,(%rsp) | |
137 87: 44 8b 4d 10 mov 0x10(%rbp),%r9d | |
138 8b: 89 c7 mov %eax,%edi | |
139 8d: e8 00 00 00 00 callq 92 <nonleaf_call+0x78> | |
140 92: c9 leaveq | |
141 93: c3 retq | |
142 | |
143 0000000000000094 <main>: | |
144 94: 55 push %rbp | |
145 95: 48 89 e5 mov %rsp,%rbp | |
146 98: 48 83 ec 10 sub $0x10,%rsp | |
147 9c: c7 44 24 08 07 00 00 00 movl $0x7,0x8(%rsp) | |
148 a4: c7 04 24 06 00 00 00 movl $0x6,(%rsp) | |
149 ab: 41 b9 05 00 00 00 mov $0x5,%r9d | |
150 b1: 41 b8 04 00 00 00 mov $0x4,%r8d | |
151 b7: b9 03 00 00 00 mov $0x3,%ecx | |
152 bc: ba 02 00 00 00 mov $0x2,%edx | |
153 c1: be 01 00 00 00 mov $0x1,%esi | |
154 c6: bf 00 00 00 00 mov $0x0,%edi | |
155 cb: e8 00 00 00 00 callq d0 <main+0x3c> | |
156 d0: b8 00 00 00 00 mov $0x0,%eax | |
157 d5: c9 leaveq | |
158 d6: c3 retq | |
159 | |
160 ; vim: ft=asm | |
161 |