如何知道第一个函数参数在哪里? [英] How to know where's the first function argument?
问题描述
PUSH EBP
MOV EBP,ESP
SUB ESP,8
LEAVE
RETN 8
并接受两个4字节的参数。看来第一个参数是 EBP + 8
,第二个参数是 EBP + 12
。但是,如何知道这一点?因为如果函数需要三个4字节的参数,那么第三个参数将位于 EBP + 16
。第一个参数是否总是在 EBP + 8
中,然后我只需添加参数大小即可获得下一个参数?如果是的话,为什么8?
感谢您提前致谢。 当使用堆栈帧时,第一个 stack 参数将始终位于 [EBP + 8]
处,但调用约定可以在两个寄存器中传递参数目的和SIMD)和堆栈上。
这个例子假设你使用了一个标准化的约定,比如 __ stdcall
, __ cdecl
,但是在 __ fastcall
和VC ++ 13新的 __ vectorcall
中的参数将用于通用SIMD寄存器(并且寄存器本身基于ABI Sys-V与MS不同)。
I was just wondering, If I have this ASM function:
PUSH EBP
MOV EBP, ESP
SUB ESP, 8
LEAVE
RETN 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?
Thanks in advance.
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.
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屋!