如何知道第一个函数参数在哪里? [英] How to know where's the first function argument?

查看:76
本文介绍了如何知道第一个函数参数在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道,如果我具有此ASM功能:

I was just wondering, If I have this ASM function:

PUSH EBP
MOV EBP, ESP
SUB ESP, 8
LEAVE
RETN 8

不执行任何操作,并接受两个4字节的参数.似乎第一个参数位于 EBP + 8 ,第二个参数位于 EBP + 12 .但是,如何知道呢?因为如果该函数采用三个4字节参数,则第三个将位于 EBP + 16 .将第一个参数始终设置为 EBP + 8 ,然后我只需要添加参数大小即可获得下一个参数?如果是,为什么是8?

That does nothing and takes two 4-bytes arguments. It seems that the first argument is at EBP+8 and the second at EBP+12. But, how to know that? Because if the function takes three 4-bytes parameters, then the third will be at EBP+16. Will the first argument be always at EBP+8 and then I just have to add the argument size to get the next one? If yes, why 8?

谢谢.

推荐答案

使用堆栈框架时,第一个 stack 参数将始终位于 [EBP + 8] ,但是调用约定可以在两个寄存器(通用寄存器和SIMD)以及堆栈中传递参数.

The first stack argument will always be at [EBP+8] when using a stack frame, but calling conventions can pass arguments in both registers (general purpose and SIMD) and on the stack.

此示例假设您使用的是标准化惯例,例如 __ stdcall __ cdecl ,但是 __ fastcall 和VC ++ 13的新 __ vectorcall 将分别是通用寄存器和SIMD寄存器(并且寄存器本身根据ABI Sys-V与MS的不同而有所不同).

This your example assume you use a standardized convention such as __stdcall, __cdecl but arguments in __fastcall and VC++13's new __vectorcall will be in general purpose and SIMD registers respectively (and the registers themselves differ based on ABI Sys-V vs MS).

这篇关于如何知道第一个函数参数在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆