Skip to content

Commit 4df18d6

Browse files
committed
update
1 parent 1f82837 commit 4df18d6

File tree

5 files changed

+260
-112
lines changed

5 files changed

+260
-112
lines changed
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
!ts.c
2-
!ts.s
1+
!ts.*
+6-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11

22
main:ts.c
3-
gcc -c -g -Wa,-adlhn $< > ts.s
3+
gcc -c -g -Wa,-adlhn $< > ts.comment.s
44

55
ass: ts.c
6-
gcc -S
6+
gcc -S -o ts.s $<
7+
8+
obj: ts.c
9+
gcc -g -c $< # And then usx 'objdump -d -M intel -S ts.o'
10+
@objdump -d -M intel -S ts.o > objdump.out
711

812
clean:
913
rm ts.s -f
+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
ts.o: file format elf64-x86-64
3+
4+
5+
Disassembly of section .text:
6+
7+
0000000000000000 <main>:
8+
#include <stdlib.h>
9+
10+
11+
int main() {
12+
0: 55 push rbp
13+
1: 48 89 e5 mov rbp,rsp
14+
4: 53 push rbx
15+
5: 48 83 ec 38 sub rsp,0x38
16+
9: 48 89 e0 mov rax,rsp
17+
c: 48 89 c3 mov rbx,rax
18+
int n;
19+
20+
int fuuuuuuuuuuuck[n];
21+
f: 8b 45 ec mov eax,DWORD PTR [rbp-0x14]
22+
12: 4c 63 c0 movsxd r8,eax
23+
15: 49 83 e8 01 sub r8,0x1
24+
19: 4c 89 45 e0 mov QWORD PTR [rbp-0x20],r8
25+
1d: 4c 63 c0 movsxd r8,eax
26+
20: 4c 89 c6 mov rsi,r8
27+
23: bf 00 00 00 00 mov edi,0x0
28+
28: 48 63 f0 movsxd rsi,eax
29+
2b: 48 89 f2 mov rdx,rsi
30+
2e: b9 00 00 00 00 mov ecx,0x0
31+
33: 48 98 cdqe
32+
35: 48 c1 e0 02 shl rax,0x2
33+
39: 48 8d 50 03 lea rdx,[rax+0x3]
34+
3d: b8 10 00 00 00 mov eax,0x10
35+
42: 48 83 e8 01 sub rax,0x1
36+
46: 48 01 d0 add rax,rdx
37+
49: b9 10 00 00 00 mov ecx,0x10
38+
4e: ba 00 00 00 00 mov edx,0x0
39+
53: 48 f7 f1 div rcx
40+
56: 48 6b c0 10 imul rax,rax,0x10
41+
5a: 48 29 c4 sub rsp,rax
42+
5d: 48 89 e0 mov rax,rsp
43+
60: 48 83 c0 03 add rax,0x3
44+
64: 48 c1 e8 02 shr rax,0x2
45+
68: 48 c1 e0 02 shl rax,0x2
46+
6c: 48 89 45 d8 mov QWORD PTR [rbp-0x28],rax
47+
int *heheheheheheheh;
48+
heheheheheheheh = (int *) malloc (888); // 为了方便观测设置为 888 (4,8的倍数) 了,没用 sizeof.
49+
70: bf 78 03 00 00 mov edi,0x378
50+
75: e8 00 00 00 00 call 7a <main+0x7a>
51+
7a: 48 89 45 d0 mov QWORD PTR [rbp-0x30],rax
52+
53+
int * const nima = (int *) malloc (444); // 同上
54+
7e: bf bc 01 00 00 mov edi,0x1bc
55+
83: e8 00 00 00 00 call 88 <main+0x88>
56+
88: 48 89 45 c8 mov QWORD PTR [rbp-0x38],rax
57+
nima[1] = 1314;
58+
8c: 48 8b 45 c8 mov rax,QWORD PTR [rbp-0x38]
59+
90: 48 83 c0 04 add rax,0x4
60+
94: c7 00 22 05 00 00 mov DWORD PTR [rax],0x522
61+
62+
63+
fuuuuuuuuuuuck[1] = 13;
64+
9a: 48 8b 45 d8 mov rax,QWORD PTR [rbp-0x28]
65+
9e: c7 40 04 0d 00 00 00 mov DWORD PTR [rax+0x4],0xd
66+
heheheheheheheh[1] = 14;
67+
a5: 48 8b 45 d0 mov rax,QWORD PTR [rbp-0x30]
68+
a9: 48 83 c0 04 add rax,0x4
69+
ad: c7 00 0e 00 00 00 mov DWORD PTR [rax],0xe
70+
71+
return 0;
72+
b3: b8 00 00 00 00 mov eax,0x0
73+
b8: 48 89 dc mov rsp,rbx
74+
}
75+
bb: 48 8b 5d f8 mov rbx,QWORD PTR [rbp-0x8]
76+
bf: c9 leave
77+
c0: c3 ret
+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
1 .file "ts.c"
2+
2 .text
3+
3 .Ltext0:
4+
4 .globl main
5+
6 main:
6+
7 .LFB2:
7+
8 .file 1 "ts.c"
8+
1:ts.c **** #include <stdlib.h>
9+
2:ts.c ****
10+
3:ts.c ****
11+
4:ts.c **** int main() {
12+
9 .loc 1 4 0
13+
10 .cfi_startproc
14+
11 0000 55 pushq %rbp
15+
12 .cfi_def_cfa_offset 16
16+
13 .cfi_offset 6, -16
17+
14 0001 4889E5 movq %rsp, %rbp
18+
15 .cfi_def_cfa_register 6
19+
16 0004 53 pushq %rbx
20+
17 0005 4883EC38 subq $56, %rsp
21+
18 .cfi_offset 3, -24
22+
19 0009 4889E0 movq %rsp, %rax
23+
20 000c 4889C3 movq %rax, %rbx
24+
5:ts.c **** int n;
25+
6:ts.c ****
26+
7:ts.c **** int fuuuuuuuuuuuck[n];
27+
21 .loc 1 7 0
28+
22 000f 8B45EC movl -20(%rbp), %eax
29+
23 0012 4C63C0 movslq %eax, %r8
30+
24 0015 4983E801 subq $1, %r8
31+
25 0019 4C8945E0 movq %r8, -32(%rbp)
32+
26 001d 4C63C0 movslq %eax, %r8
33+
27 0020 4C89C6 movq %r8, %rsi
34+
28 0023 BF000000 movl $0, %edi
35+
28 00
36+
29 0028 4863F0 movslq %eax, %rsi
37+
30 002b 4889F2 movq %rsi, %rdx
38+
31 002e B9000000 movl $0, %ecx
39+
31 00
40+
32 0033 4898 cltq
41+
33 0035 48C1E002 salq $2, %rax
42+
34 0039 488D5003 leaq 3(%rax), %rdx
43+
35 003d B8100000 movl $16, %eax
44+
35 00
45+
36 0042 4883E801 subq $1, %rax
46+
37 0046 4801D0 addq %rdx, %rax
47+
38 0049 B9100000 movl $16, %ecx
48+
38 00
49+
39 004e BA000000 movl $0, %edx
50+
39 00
51+
40 0053 48F7F1 divq %rcx
52+
41 0056 486BC010 imulq $16, %rax, %rax
53+
42 005a 4829C4 subq %rax, %rsp
54+
43 005d 4889E0 movq %rsp, %rax
55+
44 0060 4883C003 addq $3, %rax
56+
45 0064 48C1E802 shrq $2, %rax
57+
46 0068 48C1E002 salq $2, %rax
58+
47 006c 488945D8 movq %rax, -40(%rbp)
59+
8:ts.c **** int *heheheheheheheh;
60+
9:ts.c **** heheheheheheheh = (int *) malloc (888); // 为了方便观测设置为 888 (4,8的倍数) 了,
61+
48 .loc 1 9 0
62+
49 0070 BF780300 movl $888, %edi
63+
49 00
64+
50 0075 E8000000 call malloc
65+
50 00
66+
51 007a 488945D0 movq %rax, -48(%rbp)
67+
10:ts.c ****
68+
11:ts.c **** int * const nima = (int *) malloc (444); // 同上
69+
52 .loc 1 11 0
70+
53 007e BFBC0100 movl $444, %edi
71+
53 00
72+
54 0083 E8000000 call malloc
73+
54 00
74+
55 0088 488945C8 movq %rax, -56(%rbp)
75+
12:ts.c **** nima[1] = 1314;
76+
56 .loc 1 12 0
77+
57 008c 488B45C8 movq -56(%rbp), %rax
78+
58 0090 4883C004 addq $4, %rax
79+
59 0094 C7002205 movl $1314, (%rax)
80+
59 0000
81+
13:ts.c ****
82+
14:ts.c ****
83+
15:ts.c **** fuuuuuuuuuuuck[1] = 13;
84+
60 .loc 1 15 0
85+
61 009a 488B45D8 movq -40(%rbp), %rax
86+
62 009e C740040D movl $13, 4(%rax)
87+
62 000000
88+
16:ts.c **** heheheheheheheh[1] = 14;
89+
63 .loc 1 16 0
90+
64 00a5 488B45D0 movq -48(%rbp), %rax
91+
65 00a9 4883C004 addq $4, %rax
92+
66 00ad C7000E00 movl $14, (%rax)
93+
66 0000
94+
17:ts.c ****
95+
18:ts.c **** return 0;
96+
67 .loc 1 18 0
97+
68 00b3 B8000000 movl $0, %eax
98+
68 00
99+
69 00b8 4889DC movq %rbx, %rsp
100+
19:ts.c **** }
101+
70 .loc 1 19 0
102+
71 00bb 488B5DF8 movq -8(%rbp), %rbx
103+
72 00bf C9 leave
104+
73 .cfi_def_cfa 7, 8
105+
74 00c0 C3 ret
106+
75 .cfi_endproc
107+
76 .LFE2:
108+
78 .Letext0:

test_snippet/c_arrya_and_point/ts.s

+68-108
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,68 @@
1-
1 .file "ts.c"
2-
2 .text
3-
3 .Ltext0:
4-
4 .globl main
5-
6 main:
6-
7 .LFB2:
7-
8 .file 1 "ts.c"
8-
1:ts.c **** #include <stdlib.h>
9-
2:ts.c ****
10-
3:ts.c ****
11-
4:ts.c **** int main() {
12-
9 .loc 1 4 0
13-
10 .cfi_startproc
14-
11 0000 55 pushq %rbp
15-
12 .cfi_def_cfa_offset 16
16-
13 .cfi_offset 6, -16
17-
14 0001 4889E5 movq %rsp, %rbp
18-
15 .cfi_def_cfa_register 6
19-
16 0004 53 pushq %rbx
20-
17 0005 4883EC38 subq $56, %rsp
21-
18 .cfi_offset 3, -24
22-
19 0009 4889E0 movq %rsp, %rax
23-
20 000c 4889C3 movq %rax, %rbx
24-
5:ts.c **** int n;
25-
6:ts.c ****
26-
7:ts.c **** int fuuuuuuuuuuuck[n];
27-
21 .loc 1 7 0
28-
22 000f 8B45EC movl -20(%rbp), %eax
29-
23 0012 4C63C0 movslq %eax, %r8
30-
24 0015 4983E801 subq $1, %r8
31-
25 0019 4C8945E0 movq %r8, -32(%rbp)
32-
26 001d 4C63C0 movslq %eax, %r8
33-
27 0020 4C89C6 movq %r8, %rsi
34-
28 0023 BF000000 movl $0, %edi
35-
28 00
36-
29 0028 4863F0 movslq %eax, %rsi
37-
30 002b 4889F2 movq %rsi, %rdx
38-
31 002e B9000000 movl $0, %ecx
39-
31 00
40-
32 0033 4898 cltq
41-
33 0035 48C1E002 salq $2, %rax
42-
34 0039 488D5003 leaq 3(%rax), %rdx
43-
35 003d B8100000 movl $16, %eax
44-
35 00
45-
36 0042 4883E801 subq $1, %rax
46-
37 0046 4801D0 addq %rdx, %rax
47-
38 0049 B9100000 movl $16, %ecx
48-
38 00
49-
39 004e BA000000 movl $0, %edx
50-
39 00
51-
40 0053 48F7F1 divq %rcx
52-
41 0056 486BC010 imulq $16, %rax, %rax
53-
42 005a 4829C4 subq %rax, %rsp
54-
43 005d 4889E0 movq %rsp, %rax
55-
44 0060 4883C003 addq $3, %rax
56-
45 0064 48C1E802 shrq $2, %rax
57-
46 0068 48C1E002 salq $2, %rax
58-
47 006c 488945D8 movq %rax, -40(%rbp)
59-
8:ts.c **** int *heheheheheheheh;
60-
9:ts.c **** heheheheheheheh = (int *) malloc (888); // 为了方便观测设置为 888 (4,8的倍数) 了,
61-
48 .loc 1 9 0
62-
49 0070 BF780300 movl $888, %edi
63-
49 00
64-
50 0075 E8000000 call malloc
65-
50 00
66-
51 007a 488945D0 movq %rax, -48(%rbp)
67-
10:ts.c ****
68-
11:ts.c **** int * const nima = (int *) malloc (444); // 同上
69-
52 .loc 1 11 0
70-
53 007e BFBC0100 movl $444, %edi
71-
53 00
72-
54 0083 E8000000 call malloc
73-
54 00
74-
55 0088 488945C8 movq %rax, -56(%rbp)
75-
12:ts.c **** nima[1] = 1314;
76-
56 .loc 1 12 0
77-
57 008c 488B45C8 movq -56(%rbp), %rax
78-
58 0090 4883C004 addq $4, %rax
79-
59 0094 C7002205 movl $1314, (%rax)
80-
59 0000
81-
13:ts.c ****
82-
14:ts.c ****
83-
15:ts.c **** fuuuuuuuuuuuck[1] = 13;
84-
60 .loc 1 15 0
85-
61 009a 488B45D8 movq -40(%rbp), %rax
86-
62 009e C740040D movl $13, 4(%rax)
87-
62 000000
88-
16:ts.c **** heheheheheheheh[1] = 14;
89-
63 .loc 1 16 0
90-
64 00a5 488B45D0 movq -48(%rbp), %rax
91-
65 00a9 4883C004 addq $4, %rax
92-
66 00ad C7000E00 movl $14, (%rax)
93-
66 0000
94-
17:ts.c ****
95-
18:ts.c **** return 0;
96-
67 .loc 1 18 0
97-
68 00b3 B8000000 movl $0, %eax
98-
68 00
99-
69 00b8 4889DC movq %rbx, %rsp
100-
19:ts.c **** }
101-
70 .loc 1 19 0
102-
71 00bb 488B5DF8 movq -8(%rbp), %rbx
103-
72 00bf C9 leave
104-
73 .cfi_def_cfa 7, 8
105-
74 00c0 C3 ret
106-
75 .cfi_endproc
107-
76 .LFE2:
108-
78 .Letext0:
1+
.file "ts.c"
2+
.text
3+
.globl main
4+
.type main, @function
5+
main:
6+
.LFB2:
7+
.cfi_startproc
8+
pushq %rbp
9+
.cfi_def_cfa_offset 16
10+
.cfi_offset 6, -16
11+
movq %rsp, %rbp
12+
.cfi_def_cfa_register 6
13+
pushq %rbx
14+
subq $56, %rsp
15+
.cfi_offset 3, -24
16+
movq %rsp, %rax
17+
movq %rax, %rbx
18+
movl -20(%rbp), %eax
19+
movslq %eax, %r8
20+
subq $1, %r8
21+
movq %r8, -32(%rbp)
22+
movslq %eax, %r8
23+
movq %r8, %rsi
24+
movl $0, %edi
25+
movslq %eax, %rsi
26+
movq %rsi, %rdx
27+
movl $0, %ecx
28+
cltq
29+
salq $2, %rax
30+
leaq 3(%rax), %rdx
31+
movl $16, %eax
32+
subq $1, %rax
33+
addq %rdx, %rax
34+
movl $16, %ecx
35+
movl $0, %edx
36+
divq %rcx
37+
imulq $16, %rax, %rax
38+
subq %rax, %rsp
39+
movq %rsp, %rax
40+
addq $3, %rax
41+
shrq $2, %rax
42+
salq $2, %rax
43+
movq %rax, -40(%rbp)
44+
movl $888, %edi
45+
call malloc
46+
movq %rax, -48(%rbp)
47+
movl $444, %edi
48+
call malloc
49+
movq %rax, -56(%rbp)
50+
movq -56(%rbp), %rax
51+
addq $4, %rax
52+
movl $1314, (%rax)
53+
movq -40(%rbp), %rax
54+
movl $13, 4(%rax)
55+
movq -48(%rbp), %rax
56+
addq $4, %rax
57+
movl $14, (%rax)
58+
movl $0, %eax
59+
movq %rbx, %rsp
60+
movq -8(%rbp), %rbx
61+
leave
62+
.cfi_def_cfa 7, 8
63+
ret
64+
.cfi_endproc
65+
.LFE2:
66+
.size main, .-main
67+
.ident "GCC: (GNU) 4.8.2"
68+
.section .note.GNU-stack,"",@progbits

0 commit comments

Comments
 (0)