我想调用一个没有参数的函数。我知道函数的地址在EAX寄存器中。为什么不是这个代码这样做:什么推动相同的寄存器两次做?
push EAX
push EAX
ret
而这一次调用该函数:
push next_a
push EAX
ret
next_a:
next_a
是我想调用的函数。但我知道这个函数的地址位于EAX
第一个:推动EAX两次的是什么?
我想调用一个没有参数的函数。我知道函数的地址在EAX寄存器中。为什么不是这个代码这样做:什么推动相同的寄存器两次做?
push EAX
push EAX
ret
而这一次调用该函数:
push next_a
push EAX
ret
next_a:
next_a
是我想调用的函数。但我知道这个函数的地址位于EAX
第一个:推动EAX两次的是什么?
只要按照发生的事情。我们来调用函数foo
。
push eax ; address of foo on the stack
push eax ; address of foo on the stack again
ret ; picks off the top item from the stack, goes to foo
foo:
; body of function
ret ; picks off the top item from stack, which is still foo
; so invokes itself again
第二个例子:
push next_a ; address of next_a on the stack
push eax ; address of foo on the stack
ret ; picks off the top item from the stack, goes to foo
foo:
; body of function
ret ; picks off the top item from stack, which is next_a
next_a:
; execution continues here
因此,这两个版本做呼叫foo
第一。 无论如何,如果你真的只想打电话foo
(XY问题),然后使用call eax
并完成它。
next_a是我想要调用的函数。
真的吗?如果eax=next_a
那么这两段代码完全相同。
由于某种原因,该课程的教授说,第一个例子不是调用这个函数,我试图找出它为什么不能很好地工作...... –
@TalShani:嗯,它跳转到函数,但它不是真的一个'call',因为它不会推送与'call'相同的返回地址。 –
谢谢!你知道它是什么推动,而不是返回地址? –
你能发表更多的代码吗?什么是“next_a”?点击您问题下方的“修改”,并添加更多代码。 –
这是我想打电话的功能。但我知道这个函数的地址位于EAX ... –
这是我从考试中得到的一个问题。我知道简单的只是使用呼叫;但教授说第一个例子不工作,我试图找出为什么 –