comparison doc/disas_examples/arm.atpcs_arm.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 0fc22b5feac7
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(220) = '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 netbsd-4.0.1-cats w/ gcc 4.1.2
23
24 00000000 <leaf_call>:
25 0: e1a0c00d mov ip, sp
26 4: e92dd800 stmdb sp!, {fp, ip, lr, pc}
27 8: e24cb004 sub fp, ip, #4 ; 0x4
28 c: e24dd010 sub sp, sp, #16 ; 0x10
29 10: e50b0010 str r0, [fp, #-16]
30 14: e50b1014 str r1, [fp, #-20]
31 18: e50b2018 str r2, [fp, #-24]
32 1c: e50b301c str r3, [fp, #-28]
33 20: e24bd00c sub sp, fp, #12 ; 0xc
34 24: e89da800 ldmia sp, {fp, sp, pc}
35
36 00000028 <nonleaf_call>:
37 28: e1a0c00d mov ip, sp ; |
38 ;spill here, if needed: stmdb sp!, {r0, r1, r2, r3} ; | just for ref, if present this would change below offsets
39 2c: e92dd800 stmdb sp!, {fp, ip, lr, pc} ; |
40 30: e24cb004 sub fp, ip, #4 ; | prolog
41 34: e24dd020 sub sp, sp, #32 ; |
42 38: e50b0010 str r0, [fp, #-16] ; in arg 0 -> temp space in local area
43 3c: e50b1014 str r1, [fp, #-20] ; in arg 1 -> temp space in local area
44 40: e50b2018 str r2, [fp, #-24] ; in arg 2 -> temp space in local area
45 44: e50b301c str r3, [fp, #-28] ; in arg 3 -> temp space in local area
46 48: e24dd0e0 sub sp, sp, #224 ; alloca(220) - with padding to guarantee alignment
47 4c: e28d200c add r2, sp, #12 ; |
48 50: e50b2020 str r2, [fp, #-32] ; | @@@ pointless push of r2 to local area to put it back ...
49 54: e51b2020 ldr r2, [fp, #-32] ; | @@@ ... into r2
50 58: e2823003 add r3, r2, #3 ; | start of (aligned) alloca()'d memory -> r3, leaving room at top of stack for param area
51 5c: e1a03123 mov r3, r3, lsr #2 ; |
52 60: e1a03103 mov r3, r3, lsl #2 ; /
53 64: e50b3020 str r3, [fp, #-32] ; \
54 68: e51b2020 ldr r2, [fp, #-32] ; | r2 -> r3, to free r2 (kinda pointless as followup code could use r2 and r3 the other way round)
55 6c: e3a0304c mov r3, #76 ; 'L' -> r3, and ...
56 70: e5c23000 strb r3, [r2] ; ... store in local area (of alloca()'d space)
57 74: e59b3008 ldr r3, [fp, #8] ; arg 4 (fetched from prev frame's param area), and ...
58 78: e58d3000 str r3, [sp] ; ... "pushed" onto stack
59 7c: e59b300c ldr r3, [fp, #12] ; arg 5 (fetched from prev frame's param area), and ...
60 80: e58d3004 str r3, [sp, #4] ; ... "pushed" onto stack
61 84: e59b3010 ldr r3, [fp, #16] ; arg 6 (fetched from prev frame's param area), and ...
62 88: e58d3008 str r3, [sp, #8] ; ... "pushed" onto stack
63 8c: e51b0014 ldr r0, [fp, #-20] ; arg 0
64 90: e51b1018 ldr r1, [fp, #-24] ; arg 1
65 94: e51b201c ldr r2, [fp, #-28] ; arg 2
66 98: e59b3004 ldr r3, [fp, #4] ; arg 3 (fetched from prev frame's param area)
67 9c: ebfffffe bl 9c <nonleaf_call+0x74> ; return address -> r14/lr, and call
68 a0: e24bd00c sub sp, fp, #12 ; |
69 a4: e89da800 ldmia sp, {fp, sp, pc} ; | epilog
70
71 000000a8 <main>:
72 a8: e1a0c00d mov ip, sp ; |
73 ac: e92dd800 stmdb sp!, {fp, ip, lr, pc} ; |
74 b0: e24cb004 sub fp, ip, #4 ; | prolog
75 b4: e24dd010 sub sp, sp, #16 ; |
76 b8: e3a03004 mov r3, #4 ; arg 4, and ...
77 bc: e58d3000 str r3, [sp] ; ... "pushed" onto stack
78 c0: e3a03005 mov r3, #5 ; arg 5, and ...
79 c4: e58d3004 str r3, [sp, #4] ; ... "pushed" onto stack
80 c8: e3a03006 mov r3, #6 ; arg 6, and ...
81 cc: e58d3008 str r3, [sp, #8] ; ... "pushed" onto stack
82 d0: e3a03007 mov r3, #7 ; arg 7, and ...
83 d4: e58d300c str r3, [sp, #12] ; ... "pushed" onto stack
84 d8: e3a00000 mov r0, #0 ; arg 0
85 dc: e3a01001 mov r1, #1 ; arg 1
86 e0: e3a02002 mov r2, #2 ; arg 2
87 e4: e3a03003 mov r3, #3 ; arg 3
88 e8: ebfffffe bl e8 <main+0x40> ; return address -> r14/lr, and call
89 ec: e3a03000 mov r3, #0 ; return value via r3, ... (a bit unoptimal)
90 f0: e1a00003 mov r0, r3 ; ... to r0
91 f4: e24bd00c sub sp, fp, #12 ; |
92 f8: e89da800 ldmia sp, {fp, sp, pc} ; | epilog
93
94
95
96 ; output from freebsd-11.0_r260099-raspberrypi w/ clang 3.3
97
98 00000000 <leaf_call>:
99 0: e24dd030 sub sp, sp, #48 ; 0x30
100 4: e58d002c str r0, [sp, #44]
101 8: e58d1028 str r1, [sp, #40]
102 c: e58d2024 str r2, [sp, #36]
103 10: e58d3020 str r3, [sp, #32]
104 14: e59dc030 ldr ip, [sp, #48]
105 18: e58dc01c str ip, [sp, #28]
106 1c: e59dc034 ldr ip, [sp, #52]
107 20: e58dc018 str ip, [sp, #24]
108 24: e59dc038 ldr ip, [sp, #56]
109 28: e58dc014 str ip, [sp, #20]
110 2c: e58d1010 str r1, [sp, #16]
111 30: e58d300c str r3, [sp, #12]
112 34: e58d2008 str r2, [sp, #8]
113 38: e58d0004 str r0, [sp, #4]
114 3c: e28dd030 add sp, sp, #48 ; 0x30
115 40: e12fff1e bx lr
116
117 00000044 <nonleaf_call>:
118 44: e92d4bf0 push {r4, r5, r6, r7, r8, r9, fp, lr}
119 48: e28db018 add fp, sp, #24 ; 0x18
120 4c: e24ddf4a sub sp, sp, #296 ; 0x128
121 50: e50b001c str r0, [fp, #-28]
122 54: e50b1020 str r1, [fp, #-32]
123 58: e50b2024 str r2, [fp, #-36]
124 5c: e50b3028 str r3, [fp, #-40]
125 60: e59bc008 ldr ip, [fp, #8]
126 64: e50bc02c str ip, [fp, #-44]
127 68: e59bc00c ldr ip, [fp, #12]
128 6c: e50bc030 str ip, [fp, #-48]
129 70: e59bc010 ldr ip, [fp, #16]
130 74: e50bc034 str ip, [fp, #-52]
131 78: e59bc014 ldr ip, [fp, #20]
132 7c: e50bc038 str ip, [fp, #-56]
133 80: e3a0c04c mov ip, #76 ; 0x4c
134 84: e5cdc02c strb ip, [sp, #44]
135 88: e51bc020 ldr ip, [fp, #-32]
136 8c: e51be024 ldr lr, [fp, #-36]
137 90: e51b4028 ldr r4, [fp, #-40]
138 94: e51b502c ldr r5, [fp, #-44]
139 98: e51b6030 ldr r6, [fp, #-48]
140 9c: e51b7034 ldr r7, [fp, #-52]
141 a0: e51b8038 ldr r8, [fp, #-56]
142 a4: e1a0900d mov r9, sp
143 a8: e5898008 str r8, [r9, #8]
144 ac: e5897004 str r7, [r9, #4]
145 b0: e5896000 str r6, [r9]
146 b4: e58d0028 str r0, [sp, #40]
147 b8: e1a0000c mov r0, ip
148 bc: e58d1024 str r1, [sp, #36]
149 c0: e1a0100e mov r1, lr
150 c4: e58d2020 str r2, [sp, #32]
151 c8: e1a02004 mov r2, r4
152 cc: e58d301c str r3, [sp, #28]
153 d0: e1a03005 mov r3, r5
154 d4: ebfffffe bl 0 <leaf_call>
155 d8: e59d001c ldr r0, [sp, #28]
156 dc: e59d1020 ldr r1, [sp, #32]
157 e0: e59d2024 ldr r2, [sp, #36]
158 e4: e59d3028 ldr r3, [sp, #40]
159 e8: e58d0018 str r0, [sp, #24]
160 ec: e58d1014 str r1, [sp, #20]
161 f0: e58d2010 str r2, [sp, #16]
162 f4: e58d300c str r3, [sp, #12]
163 f8: e24bd018 sub sp, fp, #24 ; 0x18
164 fc: e8bd8bf0 pop {r4, r5, r6, r7, r8, r9, fp, pc}
165
166 00000100 <main>:
167 100: e92d4800 push {fp, lr}
168 104: e1a0b00d mov fp, sp
169 108: e24dd018 sub sp, sp, #24 ; 0x18
170 10c: e3a00000 mov r0, #0 ; 0x0
171 110: e50b0004 str r0, [fp, #-4]
172 114: e3a01007 mov r1, #7 ; 0x7
173 118: e1a0200d mov r2, sp
174 11c: e582100c str r1, [r2, #12]
175 120: e3a01006 mov r1, #6 ; 0x6
176 124: e5821008 str r1, [r2, #8]
177 128: e3a01005 mov r1, #5 ; 0x5
178 12c: e5821004 str r1, [r2, #4]
179 130: e3a01004 mov r1, #4 ; 0x4
180 134: e5821000 str r1, [r2]
181 138: e3a01001 mov r1, #1 ; 0x1
182 13c: e3a02002 mov r2, #2 ; 0x2
183 140: e3a03003 mov r3, #3 ; 0x3
184 144: e50b0008 str r0, [fp, #-8]
185 148: ebfffffe bl 44 <nonleaf_call>
186 14c: e51b0008 ldr r0, [fp, #-8]
187 150: e1a0d00b mov sp, fp
188 154: e8bd8800 pop {fp, pc}
189
190 ; vim: ft=asm68k
191