【问题标题】:why ecx is pushed to the stack twice,just one after another?为什么 ecx 被压入堆栈两次,一次又一次?
【发布时间】:2012-11-16 08:17:30
【问题描述】:

这里,在这个函数prologue中,ecx被连续两次压栈,为什么??

push    ebp
mov     ebp, esp

push    ecx
push    ecx
and     [ebp+var_8], 0
and     [ebp+var_4], 0
push    ebx
mov     ebx, [ebp+arg_0]
push    esi
push    edi
or      edi, 0FFFFFFFFh
push    edi             ; size_t
lea     eax, [ebp+var_8]
push    eax             ; int
mov     eax, [ebp+arg_4]
call    sub_671FF38E
push    2Eh             ; wchar_t
lea     esi, [ebp+var_8]
call    sub_673AFD82
cmp     eax, edi
jz      loc_677E564B

【问题讨论】:

  • 最好的猜测是例程的形式是void func(int n, ...) { int a=n, b=n, c=... ; func2(...); };,其中一些参数——不一定是第一个——在ecx中传递。
  • 另一种猜测是只是为了在栈上预留空间,而且两次push比sub esp, 8短。

标签: assembly


【解决方案1】:

Bo 是对的,它是分配堆栈 - 您可以看到堆栈位置在接下来的两条指令中被清零,因此实际上没有使用 ecx 值。您经常在 MSVC 编译的文件中看到这种模式。

【讨论】:

    【解决方案2】:

    它只是获取堆栈空间。

    sub esp, 8 -> 3bytes.

    推送 ecx X 2 -> 2 字节。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-26
      • 1970-01-01
      • 2014-03-03
      • 2013-11-04
      • 2012-09-02
      • 2015-10-22
      相关资源
      最近更新 更多