x64不同平台的调用约定
2015-12-31 13:18
357 查看
x64的ABI在Unix(Linux,Mac OS)上和Windows上是不同的,调用约定有区别。
wikipedia上对调用约定的解释
调用约定的不同(寄存器传参部分)
Unix:
The first six integer arguments (from the left) are passed in RDI, RSI, RDX, RCX, R8, and R9, in that order.
Additional integer arguments are passed on the stack. These registers, plus RAX, R10 and R11 are destroyed
by function calls, and thus are available for use by the function without saving.
Windows:
The first four integer arguments are passed in RCX, RDX, R8 and R9, in that order. Additional integer
arguments are passed on the stack. These registers, plus RAX, R10 and R11 are destroyed by function calls,
and thus are available for use by the function without saving.
需要注意的是,Windows上用register传参的同时,还需要需要分配栈空间,并且需要16字节对齐。
The x64 Application Binary Interface (ABI) is a 4 register fast-call calling convention, with stack-backing for those registers.
代码示例
wikipedia上对调用约定的解释
调用约定的不同(寄存器传参部分)
Unix:
The first six integer arguments (from the left) are passed in RDI, RSI, RDX, RCX, R8, and R9, in that order.
Additional integer arguments are passed on the stack. These registers, plus RAX, R10 and R11 are destroyed
by function calls, and thus are available for use by the function without saving.
Windows:
The first four integer arguments are passed in RCX, RDX, R8 and R9, in that order. Additional integer
arguments are passed on the stack. These registers, plus RAX, R10 and R11 are destroyed by function calls,
and thus are available for use by the function without saving.
需要注意的是,Windows上用register传参的同时,还需要需要分配栈空间,并且需要16字节对齐。
The x64 Application Binary Interface (ABI) is a 4 register fast-call calling convention, with stack-backing for those registers.
代码示例
---------------------------------------------------------------------- ; Allocate stack memory ; --------------------------------------------------------------------- sub rsp,8*7 ; Allocated 8*7 bytes: ; 8*4 from them are defaut parameters for all functions. ; 8*3 from them are those extra three parameters on stack. ; Total allocated space for seven parameters. ; 4x Default parameters are passed via registers. ; Those 3x extra parameters are passed via stack. ; !!! Always allocate stack space => odd number * 8, ; like now is just like we need => 8*7, doing like this will ; balance stack and make it aligned on 16 byte boundary. ; --------------------------------------------------------------------- ; Call printf with seven parameters ; 4x of them are assigned to registers. ; 3x of them are assigned to stack spaces. ; --------------------------------------------------------------------- ; #3x# ; Stack parameters mov rax,qword [param6] mov qword [rsp+48],rax mov rax,qword [param5] mov qword [rsp+40],rax mov rax,qword [param4] mov qword [rsp+32],rax ; --------------------------- ; #4x# ; Register parameters mov r9,qword [param3] mov r8,qword [param2] mov rdx,qword [param1] mov rcx,qword txt_format ; --------------------------- call printf ; --------------------------- ; --------------------------------------------------------------------- ; Release stack memory ; --------------------------------------------------------------------- add rsp,8*7
相关文章推荐
- 关于红杏的公益代理, Android Studio以及freso的编译
- Java Hibernate:调试 Jsp 时重启 Tomcat 以禁用缓存
- 知道指针地址 , 怎么取出指针指向的内容??? 0x7fff5fbff564 这种值 怎么赋值给一个变量??
- JNI - 如何将 char 转换成 jstring
- CVPR15 image retrieval reading list
- 运算符:三目运算符,运算符优先级,sizeof,自增自减,取余
- Phaser是一款专门用于桌面及移动HTML5 2D游戏开发的开源免费框架
- Yarn下的YarnChild启动个数决定参数
- Codeforces Round #269 (Div. 2) A B C
- Phaser是一款专门用于桌面及移动HTML5 2D游戏开发的开源免费框架
- BoW图像检索Python实战
- 使用IIS发布网站有多种方法,他们的使用场合也不同
- Egret是一套完整的HTML5游戏开发解决方案
- java设计模式----命令模式
- 三、获取寄存器信息
- Egret是一套完整的HTML5游戏开发解决方案
- 12月份前端资源分享
- Leetcode: Best Time to Buy and Sell Stock with Cooldown
- GMM、fisher vector、SIFT与HOG特征资料
- android 动态UI Layout 之 RelativeLayout用法