calling conventions:amd64
来源:互联网 发布:《优化设计》 编辑:程序博客网 时间:2024/05/14 07:55
The AMD64 takes the traditional x86 and expands the registers to 64 bits, naming them rax, rbx, etc. It also adds eight more general purpose registers, named simply R8 through R15.
The first four parameters to a function are passed in rcx, rdx, r8 and r9. Any further parameters are pushed on the stack. Furthermore, space for the register parameters is reserved on the stack, in case the called function wants to spill them; this is important if the function is variadic.
Parameters that are smaller than 64 bits are not zero-extended; the upper bits are garbage, so remember to zero them explicitly if you need to. Parameters that are larger than 64 bits are passed by address.
The return value is placed in rax. If the return value is larger than 64 bits, then a secret first parameter is passed which contains the address where the return value should be stored.
All registers must be preserved across the call, except for rax, rcx, rdx, r8, r9, r10, and r11, which are scratch.
The callee does not clean the stack. It is the caller's job to clean the stack.
The stack must be kept 16-byte aligned. Since the "call" instruction pushes an 8-byte return address, this means that every non-leaf function is going to adjust the stack by a value of the form 16n+8 in order to restore 16-byte alignment.
Here's a sample:
void SomeFunction(int a, int b, int c, int d, int e);void CallThatFunction(){ SomeFunction(1, 2, 3, 4, 5); SomeFunction(6, 7, 8, 9, 10);}
On entry to CallThatFunction, the stack looks like this:
Due to the presence of the return address, the stack is misaligned. CallThatFunction sets up its stack frame, which might go like this:
sub rsp, 0x28
Notice that the local stack frame size is 16n+8, so that the result is a realigned stack.
Now we can set up for the first call:
mov dword ptr [rsp+0x20], 5 ; output parameter 5 mov r9d, 4 ; output parameter 4 mov r8d, 3 ; output parameter 3 mov edx, 2 ; output parameter 2 mov ecx, 1 ; output parameter 1 call SomeFunction ; Go Speed Racer!
When SomeFunction returns, the stack is not cleaned, so it still looks like it did above. To issue the second call, then, we just shove the new values into the space we already reserved:
mov dword ptr [rsp+0x20], 10 ; output parameter 5 mov r9d, 9 ; output parameter 4 mov r8d, 8 ; output parameter 3 mov edx, 7 ; output parameter 2 mov ecx, 6 ; output parameter 1 call SomeFunction ; Go Speed Racer!
CallThatFunction is now finished and can clean its stack and return.
add rsp, 0x28 ret
Notice that you see very few "push" instructions in amd64 code, since the paradigm is for the caller to reserve parameter space and keep re-using it.
- calling conventions:amd64
- calling conventions:amd64
- Calling conventions
- Calling conventions(调用规则)
- x86 calling conventions
- Talk:X86 calling conventions
- x86 calling conventions
- x86 calling conventions
- Calling Conventions Demystified (Visual C++ calling conventions explained)
- IA-32 Function Calling Conventions
- Calling conventions 函数调用约定
- 函数调用规范解惑 Calling Conventions Demystified
- calling conventions on x86 platform --- 转载
- Function Calling Conventions and Name Decoration
- TI DSP Function Structure and Calling Conventions
- Nasm Assembly Intro - Understanding Calling Conventions (64-bit)
- Conventions
- Conventions
- [置顶] java.lang.String cannot be cast to [Ljava.lang.Object;错误的原因很邪恶
- MD5加密
- 音频和Midi基础支持
- sqlite关于The database disk image is malformed问题的解决
- Axis2+ myeclipse 开发教程 配置与发布
- calling conventions:amd64
- 无监督特征学习:模拟简单细胞、复杂细胞属性的特征(上段工作总结)
- hex_to_bin的busybox实现
- c#根据绝对路径获取 带后缀文件名、后缀名、文件名
- ArcGIS For JavaScript API continuous pan across dataline(连续的平移跨越日界线)————(六)
- 织梦dede实现内容页所有的链接新窗口打开办法
- apache ActiveMQ 介绍
- Project facet Java version 1.7 is not supported.
- 织梦页面新窗口打开,一句代码即可搞定!