Skip to content

Commit 065356e

Browse files
author
hanwen.chang
committed
iadd comments
1 parent 5c81f07 commit 065356e

File tree

2 files changed

+67
-41
lines changed

2 files changed

+67
-41
lines changed

11.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ int main(){
2121
}
2222

2323
void (*mm)(long,long,long*);
24-
mm =(void (*)(long,long,long*)) dlsym(handle, "_Z8sumstorellPl");
24+
mm =(void (*)(long,long,long*)) dlsym(handle, "add_sum");
2525
if ((error_str = dlerror()) != NULL) {
2626
fputs(error_str, stderr);
2727
exit(1);

22.s

+66-40
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,74 @@
1-
.file "22.cpp"
21
.text
3-
.globl _Z8sumstorellPl
4-
.type _Z8sumstorellPl, @function
5-
_Z8sumstorellPl:
2+
.globl add_sum
3+
.type add_sum, @function
4+
add_sum:
65
.LFB0:
7-
.cfi_startproc
8-
endbr64
9-
pushq %rbp
6+
.cfi_startproc #program start
7+
#endbr64 #TERMINATE BRANCH 64bit
8+
pushq %rbp #stack pointer
9+
10+
11+
#+----------------+
12+
#|stack pointer rbp|
13+
#+----------------+
14+
1015
.cfi_def_cfa_offset 16
1116
.cfi_offset 6, -16
12-
movq %rsp, %rbp
13-
.cfi_def_cfa_register 6
14-
movq %rdi, -24(%rbp)
15-
movq %rsi, -32(%rbp)
16-
movq %rdx, -40(%rbp)
17-
movq -24(%rbp), %rdx
18-
movq -32(%rbp), %rax
19-
addq %rdx, %rax
20-
movq %rax, -8(%rbp)
21-
movq -40(%rbp), %rax
22-
movq -8(%rbp), %rdx
23-
movq %rdx, (%rax)
17+
18+
19+
#8:64bits
20+
#: :
21+
#| whatever | <--- CFA
22+
#+----------------+
23+
#| return address | <--- %rsp == CFA - 8
24+
#+----------------+
25+
26+
27+
#: :
28+
#| whatever | <--- CFA
29+
#+----------------+
30+
#| return address |<- when c call asm, push address
31+
#+----------------+
32+
#| reserved space | <--- %rsp == CFA - 16 ,call site
33+
#+----------------+
34+
35+
36+
movq %rsp, %rbp
37+
#rbp is the base pointer, which points to the base of the current stack frame, and rsp is the stack pointer, which points to the top of the current stack frame.
38+
.cfi_def_cfa_register 6 #cfa register is rbp
39+
movq %rdi, -24(%rbp) #arg0 *(rbp-24) = rdi;
40+
movq %rsi, -32(%rbp) #arg1 *(rbp-32) = rsi;
41+
movq %rdx, -40(%rbp) #arg2
42+
movq -24(%rbp), %rdx #rdx =arg0
43+
movq -32(%rbp), %rax #rax = arg1
44+
addq %rdx, %rax #add arg0,arg1 to rax
45+
movq %rax, -8(%rbp) #*(rbp-8) = rax
46+
movq -40(%rbp), %rax #rax = arg2
47+
movq -8(%rbp), %rdx #rdx = *(rbp-8)
48+
movq %rdx, (%rax) #*rax=rdx
2449
nop
2550
popq %rbp
2651
.cfi_def_cfa 7, 8
2752
ret
28-
.cfi_endproc
29-
.LFE0:
30-
.size _Z8sumstorellPl, .-_Z8sumstorellPl
31-
.ident "GCC: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0"
32-
.section .note.GNU-stack,"",@progbits
33-
.section .note.gnu.property,"a"
34-
.align 8
35-
.long 1f - 0f
36-
.long 4f - 1f
37-
.long 5
38-
0:
39-
.string "GNU"
40-
1:
41-
.align 8
42-
.long 0xc0000002
43-
.long 3f - 2f
44-
2:
45-
.long 0x3
46-
3:
47-
.align 8
48-
4:
53+
.cfi_endproc # program end
54+
#.LFE0:
55+
#.data_tag:
56+
# .size add_sum, .-add_sum
57+
# .ident "GCC: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0"
58+
# .section .note.GNU-stack,"",@progbits
59+
# .section .note.gnu.property,"a"
60+
# .align 8
61+
# .long 1f - 0f
62+
# .long 4f - 1f
63+
# .long 5
64+
#0:
65+
# .string "GNU"
66+
#1:
67+
# .align 8
68+
# .long 0xc0000002
69+
# .long 3f - 2f
70+
#2:
71+
# .long 0x3
72+
#3:
73+
# .align 8
74+
#4:

0 commit comments

Comments
 (0)