例如:
int add(int a, int b) {
int result;
result = a + b;
return result;
}
int main(int argc, char *argv[]) {
int a,b,result;
a = 1;
b = 2;
result = add(a,b);
return 0;
}
00000000004004d6 <add>:
4004d6: 55 push %rbp
4004d7: 48 89 e5 mov %rsp,%rbp
4004da: 89 7d ec mov %edi,-0x14(%rbp)
4004dd: 89 75 e8 mov %esi,-0x18(%rbp)
4004e0: 8b 55 ec mov -0x14(%rbp),%edx
4004e3: 8b 45 e8 mov -0x18(%rbp),%eax
4004e6: 01 d0 add %edx,%eax
4004e8: 89 45 fc mov %eax,-0x4(%rbp)
4004eb: 8b 45 fc mov -0x4(%rbp),%eax
4004ee: 5d pop %rbp
4004ef: c3 retq
00000000004004f0 <main>:
4004f0: 55 push %rbp
4004f1: 48 89 e5 mov %rsp,%rbp
4004f4: 48 83 ec 20 sub $0x20,%rsp
4004f8: 89 7d ec mov %edi,-0x14(%rbp)
4004fb: 48 89 75 e0 mov %rsi,-0x20(%rbp)
4004ff: c7 45 f4 01 00 00 00 movl $0x1,-0xc(%rbp)
400506: c7 45 f8 02 00 00 00 movl $0x2,-0x8(%rbp)
40050d: 8b 55 f8 mov -0x8(%rbp),%edx
400510: 8b 45 f4 mov -0xc(%rbp),%eax
400513: 89 d6 mov %edx,%esi
400515: 89 c7 mov %eax,%edi
400517: e8 ba ff ff ff callq 4004d6 <add>
40051c: 89 45 fc mov %eax,-0x4(%rbp)
40051f: b8 00 00 00 00 mov $0x0,%eax
400524: c9 leaveq
400525: c3 retq
400526: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
40052d: 00 00 00
这里main中,标准起手之后,为什么不直接使用寄存器赋值,而是要先保存edi和rsi的值?
%edi,-0x14(%rbp)
%rsi,-0x20(%rbp)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…